ios – Swift:XCode6 Beta 5在AppDelegate中给核心数据对象带来错误

前端之家收集整理的这篇文章主要介绍了ios – Swift:XCode6 Beta 5在AppDelegate中给核心数据对象带来错误前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在用 swift编程语言开发一个应用程序.我正在使用XCode6 Beta4版本,所有的东西都运行得很顺利.我今天已将版本更新到Beta5,我在核心数据对象上得到的错误是:

>类型’NSManagedObjectContext’不符合协议’BooleanType’.
>类型’NSManagedObjectModel’不符合协议’BooleanType’.
>类型’NSPersistentStoreCoordinator’不符合协议’BooleanType’.

还附有错误的屏幕截图.

解决方法

实际上你得到的错误是NSManagedObjectContext?,NSManagedObjectModel?和NSPersistentStoreCoordinator?不确认为BooleanType协议.注意 ?类型名称末尾的问号.

所以你正在处理Optionals.由于Beta 5 Optionals不再符合BooleanType协议.

您需要明确检查nil,更改:

if !_managedObjectContext {
    // ...
}

至:

if _managedObjectContext == nil {
    // ...
}

并为_managedObjectModel和_persistentStoreCoordinator执行相同的操作.

来自xCode 6 Beta 5发行说明:

Optionals can now be compared to nil with == and !=,even if the
underlying element is not Equatable.

Optionals no longer conform to the BooleanType (formerly LogicValue) protocol,so they may no longer be used in place of boolean expressions (they must be explicitly compared with v != nil). This resolves confusion around Bool? and related types,makes code more explicit about what test is expected,and is more consistent with the rest of the language. Note that ImplicitlyUnwrappedOptional still includes some BooleanType functionality. This issue will be resolved in a future beta.

原文链接:https://www.f2er.com/iOS/332712.html

猜你在找的iOS相关文章