简体   繁体   English

类型“NSPersistentStore”在swift中不符合协议“BooleanType”

[英]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.

相关问题 类型“ AnyObject”不符合协议“ BooleanType” - Type 'AnyObject' does not conform to protocol 'BooleanType' 类型不符合协议Swift - Type does not conform to protocol Swift Swift - 类型“*”不符合协议“*” - Swift - Type '*' does not conform to protocol '*' 游乐场执行失败: <EXPR> :15:33:错误:类型&#39;Int&#39;不符合协议&#39;BooleanType&#39; - Playground execution failed: <EXPR>:15:33: error: type 'Int' does not conform to protocol 'BooleanType' 类型不符合协议序列类型 - Swift - type does not conform to protocol Sequence Type - Swift Swift:类型&#39;ViewController&#39;不符合协议&#39;UIPageViewControllerDataSource&#39; - Swift: Type 'ViewController' does not conform to protocol 'UIPageViewControllerDataSource' Swift 2.0类型&#39;()&#39;不符合协议 - Swift 2.0 Type '()' does not conform to protocol Swift:`类型&#39;[String]&#39;不符合协议&#39;StringLiteralConvertible&#39; - Swift: `Type '[String]' does not conform to protocol 'StringLiteralConvertible'` 类型“myViewController”不符合Swift中的协议UIPIckerDataSource - Type “myViewController” does not conform to protocol UIPIckerDataSource in Swift Swift - MultipeerConnectivity类型不符合协议 - Swift - MultipeerConnectivity Type does not conform to protocol
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM