此代码显示我的错误所在:
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'
我为什么要犯这个错误?
发布于 2015-11-20 17:48:03
您正在使用的函数定义:
func addPersistentStoreWithType(_ storeType: String, configuration configuration: String?, URL storeURL: NSURL?, options options: [NSObject : AnyObject]?) throws -> NSPersistentStore因此,这是一个函数,它可以抛出并返回一个持久存储。
您的代码显示为if try coordinator!.addPers...,即“如果返回的持久存储为真.”。持久化存储不是真(或假),所以它不是布尔值。您编写的代码就像状态被返回一样,但是返回了一个(非可选的)对象(假设函数不抛出)。
https://stackoverflow.com/questions/33832856
复制相似问题