Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

reading a NSDictionary from plist issue with BOOL value

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?

like image 371
xonegirlz Avatar asked Oct 06 '11 19:10

xonegirlz


2 Answers

valueForKey returns an id. Do this:

NSNumber * n = [self.data valueForKey:@"Arizona"];
BOOL value = [n boolValue];
like image 108
Colin Avatar answered Nov 15 '22 21:11

Colin


- (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);

}
like image 42
Zigglzworth Avatar answered Nov 15 '22 20:11

Zigglzworth