Ios AppDelegate类型的值没有成员managedObjectContext 代码 错误: AppDelegate类型的值没有成员managedObjectContext
我的问题是我想在Xcode 8中使用Ios AppDelegate类型的值没有成员managedObjectContext 代码 错误: AppDelegate类型的值没有成员managedObjectContext,ios,swift,core-data,xcode8,managedobjectcontext,Ios,Swift,Core Data,Xcode8,Managedobjectcontext,我的问题是我想在Xcode 8中使用managedObjectContext,但它说AppDelegate没有这样的成员。我想使用它是因为我想用核心数据为ios 9创建一个项目。 我想了解managedObjectContext的定义,如果您有解释,请发表评论: 错误很明显,它表明AppDelegate没有名为managedObjectContext的属性。检查AppDelegate并查看是否存在名为managedObjectContext的属性 参考: 在编写代码之前,了解以下内容非常重要
managedObjectContext
,但它说AppDelegate
没有这样的成员。我想使用它是因为我想用核心数据为ios 9创建一个项目。
我想了解managedObjectContext
的定义,如果您有解释,请发表评论:
- 错误很明显,它表明
没有名为AppDelegate
的属性。检查managedObjectContext
并查看是否存在名为AppDelegate
的属性managedObjectContext
- 概念-
- 循序渐进指南-
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: "temp")
container.loadPersistentStores(completionHandler: { (storeDescription, error) in
if let error = error as NSError? {
// Replace this implementation with code to handle the error appropriately.
// fatalError() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
/*
Typical reasons for an error here include:
* The parent directory does not exist, cannot be created, or disallows writing.
* The persistent store is not accessible, due to permissions or data protection when the device is locked.
* The device is out of space.
* The store could not be migrated to the current model version.
Check the error message to determine what the actual problem was.
*/
fatalError("Unresolved error \(error), \(error.userInfo)")
}
})
return container
}()
创建项目时,是否选中了
使用核心数据?还是没有检查?我想你需要参考是的,我检查了,问题是我正在为ios 9创建一个项目,xcode 8正在使用与ios 10兼容的核心数据创建appdelegate文件。它添加了persistentContainer:NSPersistentContainer,它与ios 9不兼容有一个答案,因此包括旧样式的核心数据访问的类源,但转换为Swift 3:我理解错误,但我想要我现在找到的managedObjectContext的定义。请参阅第1个链接,阅读该链接非常耗时,但会帮助您理解清楚。ManagedObjectContext就像一个便笺簿,您可以在其中进行更改。然后你可以保存上下文,问题是“我想为iOS9创建一个项目”。您在iOS 9上尝试过您的解决方案吗?是的,我想为iOS 9创建项目,所以我想检查核心数据的“appdelegate.swift”文件。如果有人有iOS 9的文件,请参考。Phillip Mills能为我提供帮助吗,Thanks@VikrantSingh-在对您的问题的评论中,有一个链接指向另一个问题,我可以给您最好的答案。
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: "temp")
container.loadPersistentStores(completionHandler: { (storeDescription, error) in
if let error = error as NSError? {
// Replace this implementation with code to handle the error appropriately.
// fatalError() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
/*
Typical reasons for an error here include:
* The parent directory does not exist, cannot be created, or disallows writing.
* The persistent store is not accessible, due to permissions or data protection when the device is locked.
* The device is out of space.
* The store could not be migrated to the current model version.
Check the error message to determine what the actual problem was.
*/
fatalError("Unresolved error \(error), \(error.userInfo)")
}
})
return container
}()
let context = persistentContainer.viewContext