'NSPersistentStore' 类型的值永远不能为 nil,不允许比较
Value of type 'NSPersistentStore' can never be nil, comparison isn't allowed
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
我就是这样处理的 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()
}
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
我就是这样处理的 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()
}