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.
YES
). You can send the message tonil
(the return value of-[NSDictionary objectForKey:]
and-[NSDictionary valueForKey:]
when the key is not present in the dictionary) without checking first if you're OK with a default ofNO
. developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/… – Lionhearted