How to dynamically compose a bitmask?
- by mystify
Lets say I have to provide an value as bitmask.
NSUInteger options = kFoo | kBar | kFooBar;
and lets say that bitmask is really huge and may have 100 options. But which options I have, depends on a lot of situations. How could I dynamically compose such a bitmask?
Is this valid?
NSUInteger options;
if (foo) {
options = options | kFoo;
}
if (bar) {
options = options | kBar;
}
if (fooBar) {
options = options | kFooBar;
}
(despite the fact that this would probably crash when doing that | bitmask operator thing to "nothing".