An automatically generated subclass of NSManagedObject for a boolean attribute raises a warning

In the CoreData model, I have an object called TestEntity. This object has one attribute named "deleted", which is of type boolean.

If I create an automatic subclass of NSManagedObject for this object using Xcode, the generated class header looks like this:

@interface TestEntity : NSManagedObject @property (nonatomic, retain) NSNumber * deleted; @end 

I understand why NSNumber is used for the boolean attribute. This has not changed before. The problem is that now it shows me 2 warnings:

  • the getter attribute in the "deleted" property does not match the property inherited from "NSManagedObject".
  • Property type "NSNumber *" is not compatible with type "BOOL" (aka "bool") inherited from "NSManagedObject".

I do not want to use primitive types. Any ideas how to get rid of these warnings? It could be a bug with Xcode 6 beta 7 (iOS 8 beta 5) that I am using. An error report has already been registered, since an automatically generated class using Xcode should not lead to a compiler warning in any case.

+5
source share
2 answers

You managed to use an attribute whose name collides with existing NSManagedObject methods.

Decision. Change the attribute name. Do not call it โ€œremote,โ€ but something else.

+8
source

I went to the NSManagetObject header file and it seems that Apple uses it that way.

 // state - methods can be used through KVC, for example for enabling/disabling widgets based on the state of the object @property (nonatomic, getter=isInserted, readonly) BOOL inserted; @property (nonatomic, getter=isUpdated, readonly) BOOL updated; @property (nonatomic, getter=isDeleted, readonly) BOOL deleted; 

Try just changing the attribute name of your entity, and I assume that it will not be an easy transfer of Core Data. Be sure to check this before submitting the code.

I donโ€™t know if Apple did this, but I didnโ€™t receive a warning in iOS 7. I hope this is a signal from Apple letting us know that they fix all problems with the main data :)

+2
source

Source: https://habr.com/ru/post/1202152/


All Articles