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语法修复它?
谢谢
'NSPersistentStore'类型的值永远不能为零,比较不是 允许
呼叫可以抛出,但它没有标记为“尝试”并且未处理错误
答案 0 :(得分:0)
这就是我用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()
}