【iOS】Swift3 报错:Value of type 'AppDelegate' has no member 'managedObjectContext',UIApplication has no

来源:互联网 发布:python 命令行输入 编辑:程序博客网 时间:2024/04/28 12:40

Swift3 报错:Value of type ‘AppDelegate’ has no member ‘managedObjectContext’,UIApplication has no member ‘sharedApplication’

在Swift 3里面,需要通过viewContext访问managedObjectContext,且sharedApplication方法改为shared方法:

var context = (UIApplication.shared.delegate as! AppDelegate).persistentContainer.viewContext

以前是这样写的:

var context = (UIApplication.sharedApplication.delegate as AppDelegate).managedObjectContext
0 0
原创粉丝点击