在Swift 3里面,需要通过viewContext访问managedObjectContext,且sharedApplication方法改为shared方法:
|
1 |
var context = (UIApplication.shared.delegate as! AppDelegate).persistentContainer.viewContext |
以前是这样写的:
|
1 |
var context = (UIApplication.sharedApplication.delegate as AppDelegate).managedObjectContext |