繁体   English   中英

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

[英]Type 'NSPersistentStore' does not conform to protocol 'BooleanType' in swift

此代码显示我的错误所在的位置:

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... ,即“如果返回的持久存储为真,则...”。 持久存储不是真(或假),所以它不是布尔值。 您编写的代码就像返回状态一样,但返回了(非可选)对象(假设函数没有抛出)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM