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.
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];
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