面对问题"值类型'AppDelegate'没有成员'managedObjectContext'在新的Xcode 8中(使用Swift 3,iOS 10)尝试在View Controller中创建新的上下文时
let context = (UIApplication.shared().delegate as! AppDelegate).managedObjectContext
Run Code Online (Sandbox Code Playgroud)
在Xcode 8中,AppDelegate.swift文件中没有managedObjectContext的代码.AppDelegate.swift中的核心数据堆栈代码仅显示:lazy var persistentContainer:NSPersistentContainer属性和func saveContext().没有managedObjectContext属性.
如何在Xcode 8)中使用Swift 3创建managedObjectContext,或者可能没有必要使用Swift 3来创建它?
我想通过这个示例代码来处理,其中使用Swift和CoreData来创建表.但是,使用Swift 3我无法使用它.最重要的是,我无法正确更换线路
// set up the NSManagedObjectContext
let appDelegate = NSApplication.sharedApplication().delegate as! AppDelegate
managedContext = appDelegate.managedObjectContext
Run Code Online (Sandbox Code Playgroud)
即使我发现了这个相关的问题(然而iOS不是OS X).如何替换产生错误消息的那段代码Value of type 'AppDelegate' has no member 'managedContext'?
我在我的应用程序中使用核心数据.我希望该应用程序在iOS 9中打开,但事实并非如此.我该如何解决?
本节给出了警告.如何让它在iOS 9和iOS 10上运行?
lazy var persistentContainer: NSPersistentContainer = {
/*
The persistent container for the application. This implementation
creates and returns a container, having loaded the store for the
application to it. This property is optional since there are legitimate
error conditions that could cause the creation of the store to fail.
*/
let container = NSPersistentContainer(name: "IndirimiKovala")
container.loadPersistentStores(completionHandler: { (storeDescription, error) in
if let error = error as NSError? {
// Replace this implementation with code to …Run Code Online (Sandbox Code Playgroud)