BOOL wrapper? Make an object of `BOOL` value. (Objective-C)

Shade picture Shade · May 12, 2011 · Viewed 7.5k times · Source

How do I wrap a BOOL in an object type in Objective-C?

I want to store a BOOL in the userInfo object of an NSTimer. How do I wrap it?

Answer

Eimantas picture Eimantas · May 12, 2011
NSNumber *boolForUserInfo = @YES; // or [NSNumber numberWithBool:YES] the old way
[userInfo setObject:boolForUserInfo forKey:@"myBool"];

Retrieve with:

[[userInfo objectForKey:@"myBool"] boolValue];