mootymoots
mootymoots

Reputation: 4575

Synthesize a BOOL to set value in Objective C

I have created a BOOL attribute in my Core Data entity called "useSystem". Additionally in order for me to get/set the data I have created an object, however whenever I try to set the synthesized BOOL I get a bus error. This is my code:

@property (nonatomic) const BOOL useSystem;

So I'm doing

[object setUseSystem:YES];

And immediately I get the bus error. Can anyone help?

Upvotes: 4

Views: 6934

Answers (3)

Nimrod
Nimrod

Reputation: 5133

This should work if you declare the method explicitly but it might not work with @synthesize. Seems like I've done this before, but maybe I just used the BOOL with no mutator method. (You can use @property without @synthesize if you define the method(s) that @property declares.)

Upvotes: 0

Stefan Arentz
Stefan Arentz

Reputation: 34935

It is probably better style to use NSNumber as the property type actually. This is also what happens when you use the model editor in xcode to add a boolean attribute to an entity. There is 'auto-boxing' going on but I always seem to have less troubles when I just use the higher level Objective-C types and wrappers like NSNumber.

Upvotes: 1

Eimantas
Eimantas

Reputation: 49344

Use [NSNumber numberWithBool:YES]

Upvotes: 6

Related Questions