gpt4 book ai didi

ios - 'NSPersistentStore' 类型的值永远不能为 nil,不允许比较

转载 作者:行者123 更新时间:2023-11-28 08:34:52 25 4
gpt4 key购买 nike

let managedModel:NSManagedObjectModel = NSManagedObjectModel.mergedModelFromBundles(nil)!


var storeCoordinator:NSPersistentStoreCoordinator = NSPersistentStoreCoordinator(managedObjectModel: managedModel)

if storeCoordinator.addPersistentStoreWithType(NSSQLiteStoreType, configuration: nil, URL: url, options: nil) != nil{
if error != nil{
print(error!.localizedDescription)
abort()
}
}

如何在最新的 swift2 语法中修复它?
谢谢

Value of type 'NSPersistentStore' can never be nil, comparison isn't allowed
Call can throw, but it is not marked with 'try' and the error is not handled

enter image description here

最佳答案

这就是我用 Swift 2 处理它的方式:

let managedModel:NSManagedObjectModel = NSManagedObjectModel.mergedModelFromBundles(nil)!
var storeCoordinator:NSPersistentStoreCoordinator = NSPersistentStoreCoordinator(managedObjectModel: managedModel)

do {
try storeCoordinator.addPersistentStoreWithType(NSSQLiteStoreType, configuration: nil, URL: url, options: nil)
} catch let error as NSError {
print(error!.localizedDescription)
abort()
}

关于ios - 'NSPersistentStore' 类型的值永远不能为 nil,不允许比较,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38085806/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com