how do i check if a BOOL is set in objective-c (iphone)?
i know that it can be done with an int or float this way: NSNumber *Num = [prefs floatForKey:@"key"]; for example
how do i check if a BOOL is set in objective-c (iphone)?
i know that it can be done with an int or float this way: NSNumber *Num = [prefs floatForKey:@"key"]; for example
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.
You can use something like this instead...
@import Foundation;
@interface CSBool : NSObject
+ (CSBool *)construct:(BOOL)value;
@property BOOL value;
@end
#import "CSBool.h"
@implementation CSBool
+ (CSBool *)construct:(BOOL)value {
CSBool *this = [self new];
this.value = value;
return this;
}
@end