此代码显示我的错误所在的位置:
do {
//error showing at this line
if try coordinator!.addPersistentStoreWithType(NSSQLiteStoreType, configuration:nil, URL: url, options:nil) {
coordinator = nil
// Report any error we got.
var dict = [String: AnyObject]()
dict[NSLocalizedDescriptionKey] = "Failed to initialize the application's saved data"
dict[NSLocalizedFailureReasonErrorKey] = failureReason
dict[NSUnderlyingErrorKey] = error
error = NSError(domain: "YOUR_ERROR_DOMAIN", code: 9999, userInfo: dict)
NSLog("Unresolved error \(error), \(error!.userInfo)")
abort()
}
} catch {
print(error)
}
编译器给出此错误:Type 'NSPersistentStore' does not conform to protocol 'BooleanType'
为什么会出现此错误?
最佳答案
您正在使用的函数定义:
func addPersistentStoreWithType(_ storeType: String, configuration configuration: String?, URL storeURL: NSURL?, options options: [NSObject : AnyObject]?) throws -> NSPersistentStore
所以这是一个可以抛出并返回持久存储的函数。
您的代码说 if try coordinator!.addPers...
,即“如果返回的持久存储为真,则...”。持久存储不是 true(或 false),因此它不是 bool 值。您编写的代码就像返回一个状态,但返回一个(非可选)对象(假设函数没有抛出)。
关于ios - 类型 'NSPersistentStore' 在 swift 中不符合协议(protocol) 'BooleanType',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33832856/