我将一些数据从viewcontroller&从另一个视图控制器获取它.下面是应用程序委托的代码
class AppDelegate: UIResponder,UIApplicationDelegate { var window: UIWindow? var navigationController: UINavigationController? var mainDic:NSMutableDictionary?
代码设置mainDic
func filterResponse(response:NSDictionary){ var appDelegate=AppDelegate() appDelegate.mainDic=response.mutablecopy() as? NSMutableDictionary }
代码来获取字典.
let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate println(appDelegate.mainDic)
问题是我得到的输出没有.请让我正确.
解决方法
这是你的错误
var appDelegate=AppDelegate() //You create a new instance,not get the exist one
尝试将您的代码更改为此
func filterResponse(response:NSDictionary){ var appDelegate= UIApplication.sharedApplication().delegate as! AppDelegate appDelegate.mainDic=response.mutablecopy() as? NSMutableDictionary }