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:
Type 'NSManagedObjectContext
' does not conform to protocol 'BooleanType
'.
Type 'NSManagedObjectModel
' does not conform to protocol 'BooleanType
'.
Type 'NSPersistentStoreCoordinator
' does not conform to protocol 'BooleanType
'.
Screenshot of errors is also attached.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With