[英]Type 'NSPersistentStore' does not conform to protocol 'BooleanType' in swift
This code displays where my error is located:此代码显示我的错误所在的位置:
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)
}
Compiler gives this error: Type 'NSPersistentStore' does not conform to protocol 'BooleanType'
编译器给出这个错误:
Type 'NSPersistentStore' does not conform to protocol 'BooleanType'
Why am I getting this error?为什么我收到这个错误?
The function definition you're using:您正在使用的函数定义:
func addPersistentStoreWithType(_ storeType: String, configuration configuration: String?, URL storeURL: NSURL?, options options: [NSObject : AnyObject]?) throws -> NSPersistentStore
so this is a function which can throw and which returns a persistent store.所以这是一个可以抛出并返回一个持久存储的函数。
Your code says if try coordinator!.addPers...
, which is 'if the persistent store returned is true then...'.您的代码表示
if try coordinator!.addPers...
,即“如果返回的持久存储为真,则...”。 A persistent store isn't true (or false), so it isn't a boolean.持久存储不是真(或假),所以它不是布尔值。 You've written the code like a status is returned, but a (non-optional) object is returned (assuming the function doesn't throw).
您编写的代码就像返回状态一样,但返回了(非可选)对象(假设函数没有抛出)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.