How to use a boolean property in objective C class, i did it like:
@property (nonatomic, copy) BOOL *locationUseBool;
but it gives error that:
Property with 'copy' attribute must be of object type.
what is the correct way of declaring?
To set a BOOL, you need to wrap the number in a value object with [NSNumber numberWithBool:NO] . But there's little reason to do that. Key-Value Coding is a roundabout way to accomplish this.
A boolean is binary value expressed in Objective-C as the primitive type BOOL which can hold either YES or NO (true or false) values. Their primary use in programming is in decision making.
@property offers a way to define the information that a class is intended to encapsulate. If you declare an object/variable using @property, then that object/variable will be accessible to other classes importing its class.
' The ' bool ' type can store only two values: true or false . To create a variable of type bool, do the same thing you did with int or string . First write the type name, ' bool ,' then the variable name and then, probably, the initial value of the variable.
You can declare this way also.
@property (assign) BOOL locationUseBool;
Basically, if you say nonatomic, and you generate the accessors using @synthesize, then if multiple threads try to change/read the property at once, badness can happen. You can get partially-written values or over-released/retained objects
In a multi-threaded program, an atomic operation cannot be interrupted partially through, whereas nonatomic operations can.
@property (nonatomic, assign) BOOL locationUseBool;
No asterisk, no copy, no retain.
This one worked for me.
@property (nonatomic) BOOL locationUseBool;
There is not asterisk * symbol in property declaration. Also, use of 'assign' is optional.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With