Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

automatically generated subclass of NSManagedObject for a boolean attribute causes a warning

In CoreData Model I have an entity called TestEntity. This entity has a single attribute named 'deleted' which is of type boolean.

If I generate an automatic NSManagedObject subclass for this entity 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 a boolean attribute. This hasn't changed from before. The problem is that it now shows me 2 warnings:

  1. getter attribute on property 'deleted' does not match the property inherited from 'NSManagedObject'.
  2. Property type 'NSNumber *' is incompatible with type 'BOOL' (aka 'bool') inherited from 'NSManagedObject'.

I don't want to use primitive types. Any ideas how to get rid of these warnings? This could be a bug with Xcode 6 beta 7 (iOS 8 beta 5) that I am using. Already filed a bug report since the automatically generated class using Xcode should not result in a compiler warning in any case.

like image 315
Arash Avatar asked Sep 09 '14 12:09

Arash


2 Answers

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

Solution: Change the name of the attribute. Don't call it "deleted" but something else.

like image 136
gnasher729 Avatar answered Sep 22 '22 09:09

gnasher729


I went to the NSManagetObject header file and it seems like Apple is using it this 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 my guess is that it won't be a light weight Core Data migration case. Make sure to check this before submitting your code.

I don't know if Apple just did this but I wasn't getting a Warning in iOS 7. Let's hope that this is a signal from Apple letting us know that they are fixing all the Core Data issues :)

like image 36
Raul Lopez Avatar answered Sep 24 '22 09:09

Raul Lopez