Alex Rivera | Logout

What is the type for boolean attributes in Core Data entities?

Asked 2009-06-20T19:10:14.320
14

I am using Core Data programmatically (i.e. not using .xcdatamodel data model files) in much the same manner as depicted in Apple's Core Data Utility Tutorial. So my problem is that when I try to add an attribute to an entity with the type NSBooleanAttributeType, it gets a bit buggy. When I add it to my NSManagedObject subclass header file (in the tutorial, that would be Run.h) as

@property (retain) BOOL *booleanProperty;

compiling fails, saying error: property 'booleanProperty' with 'retain' attribute must be of object type.

It seems like some places in Cocoa use NSNumber objects to represent booleans, so I tried setting it to

@property (retain) NSNumber *booleanProperty;

instead. However, this evokes the following runtime errors:

*** -[NSAttributeDescription _setManagedObjectModel:]: unrecognized selector sent to instance 0x101b470
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSAttributeDescription _setManagedObjectModel:]: unrecognized selector sent to instance 0x101b470'

Using GDB, I am able to trace this back to the line in my source code where I add my entity to the managed object model:

[DVManagedObjectModel setEntities:[NSArray arrayWithObjects:myEntityWithABooleanAttribute, myOtherEntity]];

So my question is this: what type should I set booleanProperty to in my custom class header?

Edit
Report

1 Answer

18

Try:

@property (nonatomic) BOOL booleanProperty;

The problem was that you used the retain in the property definition. For that you must have a property for an Objective-C class (it should be able to understand the 'retain' method). BOOL is not a class but an alias for signed char.

answered 2009-06-20T19:38:27.477

Your Answer