Synthesize BOOL to set a value in Objective-C

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

@property (nonatomic) const BOOL useSystem; 

So i do

 [object setUseSystem:YES]; 

And right away I get a bus error. Can anyone help?

+4
source share
3 answers

Use [NSNumber numberWithBool:YES]

+6
source

It is probably best to use the NSNumber style as a property type. This also happens when you use the model editor in xcode to add a boolean attribute to an entity. There is auto-boxing, but I always have less trouble when I simply use higher-level Objective-C types and wrappers such as NSNumber.

+1
source

This should work if you declare the method explicitly, but may not work with @synthesize. It looks like I did this before, but maybe I just used BOOL without the mutator method. (You can use @property without @synthesize if you define a method (s) that @property declares.)

0
source

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


All Articles