因此,当我尝试将我的部署目标设置为 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
}()
查看不同的 SO 问题/答案很明显,我需要添加一些代码来区分 iOS 10 是否可用。Swift 3 本身建议使用@available(iOS 10.0, *)
. 但这还不够。我希望这是因为我错过了“如果不可用,请使用它”,但是对于 Swift 和 iOS 编程来说,我不知道具体要写什么。而且我似乎找不到任何答案来给出关于写什么的确切答案。有人可以帮忙吗?