简体   繁体   English

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

[英]Swift: XCode6 Beta 5 giving errors on core data objects in AppDelegate

I am developing an application in swift programming language. 我正在用swift编程语言开发一个应用程序。 I was using the XCode6 Beta4 version and all the things were running smoothly and fine. 我使用的是XCode6 Beta4版本,所有的东西都运行得很顺利。 I have updated the version to Beta5 today and I am getting the errors on core data objects which are: 我今天已经将版本更新到Beta5,我在核心数据对象上得到的错误是:

  1. Type ' NSManagedObjectContext ' does not conform to protocol ' BooleanType '. 类型' NSManagedObjectContext '不符合协议' BooleanType '。

  2. Type ' NSManagedObjectModel ' does not conform to protocol ' BooleanType '. 类型' NSManagedObjectModel '不符合协议' BooleanType '。

  3. Type ' NSPersistentStoreCoordinator ' does not conform to protocol ' BooleanType '. 类型' NSPersistentStoreCoordinator '不符合协议' BooleanType '。

Screenshot of errors is also attached. 还附有错误的屏幕截图。

在此输入图像描述

Actually you are getting the error that NSManagedObjectContext? 实际上你得到NSManagedObjectContext?的错误NSManagedObjectContext? , NSManagedObjectModel? NSManagedObjectModel? and NSPersistentStoreCoordinator? NSPersistentStoreCoordinator? do not confirm to BooleanType protocol. 不要确认BooleanType协议。 Notice ? 注意? question mark at the end of the type name. 类型名称末尾的问号。

So you are dealing with Optionals. 所以你正在处理Optionals。 Since Beta 5 Optionals does not conform to BooleanType protocol anymore. 由于Beta 5 Optionals不再符合BooleanType协议。

You need to check for nil explicitly, change: 您需要明确检查nil ,更改:

if !_managedObjectContext {
    // ...
}

to: 至:

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

And do the same for _managedObjectModel and _persistentStoreCoordinator . 并为_managedObjectModel_persistentStoreCoordinator执行相同的_persistentStoreCoordinator

From xCode 6 Beta 5 Release Notes: 来自xCode 6 Beta 5发行说明:

Optionals can now be compared to nil with == and !=, even if the underlying element is not Equatable. 现在可以使用==和!=将Optionals与nil进行比较,即使底层元素不是Equatable也是如此。

and

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). Optionals不再符合BooleanType(以前的LogicValue)协议,因此它们可能不再用于代替布尔表达式(它们必须与v!= nil明确比较)。 This resolves confusion around Bool? 这解决了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. 请注意,ImplicitlyUnwrappedOptional仍包含一些BooleanType功能。 This issue will be resolved in a future beta. 此问题将在未来的测试版中得到解决。

尝试if _managedObjectContext == nil而不是!if _managedObjectContext并对persistentStoreCoordinator执行相同的操作,因为apple使用x4bode beta 5 update更改了BooleanType(而不仅仅是if)。

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

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