How do those bitmasks actually work?

Posted by mystify on Stack Overflow See other posts from Stack Overflow or by mystify
Published on 2010-03-31T17:31:57Z Indexed on 2010/03/31 17:53 UTC
Read the original article Hit count: 473

Filed under:
|
|
|

For example, this method from NSCalendar takes a bitmask:

- (NSDate *)dateByAddingComponents:(NSDateComponents *)comps toDate:(NSDate *)date options:(NSUInteger)opts

So options can be like:

NSUInteger options = kCFCalendarUnitYear;

or like:

NSUInteger options = kCFCalendarUnitYear | kCFCalendarUnitMonth | kCFCalendarUnitDay;

What I don't get is, how is this actually done? I mean: How can they pull out those values which are merged into options? If I wanted to program something like this, that can take a bitmask, how would that look?

© Stack Overflow or respective owner

Related posts about iphone

Related posts about objective-c