Check if a BOOL is set (can't be done with ==nil)

You can't. A BOOL is either YES or NO. There is no other state. The way around this would be to use an NSNumber ([NSNumber numberWithBool:YES];), and then check to see if the NSNumber itself is nil. Or have a second BOOL to indicate if you've altered the value of the first.


Annoyingly, Objective-C has no Boolean class. It certainly feels like it should and that trips a lot of people up. In collections and core data, all bools are stored as NSNumber instances.

It's really annoying having to convert back and forth all the time.


By default, a bool value is set to 0 in Objective-C, so you don't need to check if your bool value is nil anytime.