Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Restoring a BOOL inside an NSDictionary from a plist file

I have a plist file which contains an array of dictionaries. Here is one of them:

Fred Dictionary
Name Fred
isMale [box is checked]

So now I am initializing my Person object with the dictionary I read from the plist file:

 -(id) initWithDictionary: (NSDictionary *) dictionary {     if (self = [super init])     self.name = [dictionary valueForKey: @"Name"];     self.isMale = ????   } 

How do I finish off the above code so that self.isMale is set to YES if the box is checked in the plist file, and NO if it isn't. Preferably also set to NO if there is no key isMale in the dictionary.

like image 455
William Jockusch Avatar asked Sep 29 '10 14:09

William Jockusch


1 Answers

BOOL values usually stored in obj-c containers wrapped in NSNumber object. If it is so in your case then you can retrieve bool value using:

self.isMale = [[dictionary objectForKey:@"isMale"] boolValue]; 
like image 172
Vladimir Avatar answered Oct 14 '22 10:10

Vladimir