Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

ios

swift

xcode6

I am developing an application in swift programming language. I was using the XCode6 Beta4 version and all the things were running smoothly and fine. I have updated the version to Beta5 today and I am getting the errors on core data objects which are:

  1. Type 'NSManagedObjectContext' does not conform to protocol 'BooleanType'.

  2. Type 'NSManagedObjectModel' does not conform to protocol 'BooleanType'.

  3. Type 'NSPersistentStoreCoordinator' does not conform to protocol 'BooleanType'.

Screenshot of errors is also attached.

enter image description here

like image 329
Aleem Ahmad Avatar asked Aug 06 '14 10:08

Aleem Ahmad


1 Answers

Actually you are getting the error that NSManagedObjectContext?, NSManagedObjectModel? and NSPersistentStoreCoordinator? do not confirm to BooleanType protocol. Notice ? question mark at the end of the type name.

So you are dealing with Optionals. Since Beta 5 Optionals does not conform to BooleanType protocol anymore.

You need to check for nil explicitly, change:

if !_managedObjectContext {
    // ...
}

to:

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

And do the same for _managedObjectModel and _persistentStoreCoordinator.

From xCode 6 Beta 5 Release Notes:

Optionals can now be compared to nil with == and !=, even if the underlying element is not 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). 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.

like image 79
Keenle Avatar answered Oct 10 '22 16:10

Keenle