Ste*_* L. 1 core-data deployment-target ios swift3
因此,当我尝试将部署目标设置为iOS 9时(实际上低于10.0),我会收到标题中所述的错误.
这里存在的问题是:
// MARK: - Core Data stack
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: "Keebin_development_1")
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
}()
Run Code Online (Sandbox Code Playgroud)
看看不同的SO问题/答案,很明显我需要添加一些代码来区分iOS 10是否可用.Swift 3本身建议使用@available(iOS 10.0, *).但这还不够.我希望它是因为我错过了"if not available use this",但是对于Swift和iOS编程来说是新手,我不确定要具体写什么.我似乎无法找到任何答案给出关于写什么的确切答案.有人可以帮忙吗?
我遇到了同样的问题,我通过下面提到的方式解决了.我在Swift 3.0中做项目.
APpDelegate由这条线导入"import INSPersistentContainer"NSPersistentContainer用INSPersistentContainer就这样.
现在我可以在较低版本的iOS(<iOS 10)中运行我的应用程序.