How to convert and compare NSNumber to BOOL?

You currently compare two pointers. Use NSNumbers methods instead to actually compare the two:

if([someNSNumberValue isEqualToNumber:[NSNumber numberWithBool:NO]]) {
    // ...
}

To get the bool value from a NSNumber use -(BOOL)boolValue:

BOOL b = [num boolValue];

With that the comparison would be easier to read for me this way:

if([num boolValue] == NO) {
    // ...
}

Swift 4:

let newBoolValue = nsNumberValue.boolValue

enter image description here


NSUserDefaults has two methods to transparently operate with booleans:

- (BOOL)boolForKey:(NSString *)defaultName

- (void)setBool:(BOOL)value forKey:(NSString *)defaultName