Restoring a BOOL inside an NSDictionary from a plist file Restoring a BOOL inside an NSDictionary from a plist file objective-c objective-c

Restoring a BOOL inside an NSDictionary from a plist file


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


Vladimir is right, I'm just going to chime in and say it is good to check that those values from the plist exist as well, and if not set it to a default value usually.

Something like:

id isMale = [dictionary valueForKey:@"isMale"];self.isMale = isMale ? [isMale boolValue] : NO;

Which checks to see if the value for the key "isMale" exists in the dictionary. If it does then it gets the boolValue from it. If it does not then it sets self.isMale to the default of NO.


It's possible to use new format:

Bool isMale = [dictionary[@"isMale"] boolValue]