Basically, I have a custom NSObject with a lot of boolean variables. I would like to know if there is a way to modify these variables (from outside this class) without creating a property for each one. Is this possible? Thanks in advance!
Here is part of my object’s header:
@interface Polygons : NSObject {
//BOOL values for attributes
BOOL parallelogram;
BOOL rhombus;
BOOL square;
...
}
Use a bitmask to represent a set of related boolean properties. First, define an enum like so:
You can optionally provide a corresponding typedef statement:
Then you can define a property to allow outside callers to access the bitmask:
Calling code can then access the property to get or set the bitfield. Note that you can use the bitwise OR operator to specify multiple values:
EDIT
For more info on how to work with a bitmask, see the following:
How do those bitmasks actually work?
http://en.wikipedia.org/wiki/Mask_(computing)
http://en.wikipedia.org/wiki/Bitwise_operation