Swift: XCode6 Beta 5 gives errors in core data objects in AppDelegate

I am developing an application in the swift programming language. I used the Xcode6 Beta4 version and everything was smooth and beautiful. I upgraded to Beta5 today and I get errors in the main data objects, which are:

  • The type ' NSManagedObjectContext ' does not conform to the ' BooleanType ' protocol.

  • The type ' NSManagedObjectModel ' does not conform to the ' BooleanType ' protocol.

  • The type ' NSPersistentStoreCoordinator ' does not conform to the ' BooleanType ' protocol.

Also included is a screenshot of the errors.

enter image description here

+7
ios swift xcode6
source share
2 answers

You actually get the error message, what is NSManagedObjectContext? NSManagedObjectModel? and NSPersistentStoreCoordinator? do not confirm the BooleanType protocol. Pay attention to ? question mark at the end of the type name.

So you are dealing with Optionals. Because Beta 5 Optionals no longer conforms to the BooleanType protocol.

You need to explicitly specify nil , change:

 if !_managedObjectContext { // ... } 

in

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

And do the same for _managedObjectModel and _persistentStoreCoordinator .

From xCode 6 Beta 5 Release Notes:

Options can now be compared with nil with == and! =, even if the base element is not Equableable.

and

Options no longer conform to the BooleanType (formerly LogicValue) protocol, so they can no longer be used instead of boolean (they must be explicitly mapped to v! = Nil). Does this resolve the confusion around Boul? and the types associated with them, makes the code more explicit about which test is expected, and more consistent with the rest of the language. Note: ImplicitlyUnwrappedOptional still includes some BooleanType features. This issue will be resolved in a future beta.

+14
source share

Try if _managedObjectContext == nil instead of !if _managedObjectContext and do the same with persistentStoreCoordinator , because the apple changed something using BooleanType (and not just if) with the xCode beta 5 update.

+1
source share

All Articles