So I have the following method:
- (void)readPlist
{
NSString *path = [[NSBundle mainBundle] pathForResource:@"States" ofType:@"plist"];
self.data = [[NSMutableDictionary alloc] initWithContentsOfFile:path];
BOOL value = (BOOL)[self.data valueForKey:@"Arizona"];
NSLog(@"VALUE IS %d", value);
}
It reads the plist fine, it can detect that it has 7 keys, however when I try to print the value out it gives me 32 if it's a no and 24 if it's a yes. What am I doing wrong?
valueForKey returns an id. Do this:
NSNumber * n = [self.data valueForKey:@"Arizona"];
BOOL value = [n boolValue];
- (void)readPlist
{
NSString *path = [[NSBundle mainBundle] pathForResource:@"States" ofType:@"plist"];
self.data = [[NSMutableDictionary alloc] initWithContentsOfFile:path];
BOOL value = [[self.data valueForKey:@"Arizona"] intValue];
NSLog(@"VALUE IS %i", value);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With