On Jul 21, 2010, at 4:29 PM, Clark Williams wrote: Now the question. How do I reference the BOOL? If I try the following: BOOL widget = @(BOOL *)[temp objectForKey:@"strKey4"]; I get a bad value. If I try anything with the RHS set to: (BOOL*)[temp objectForKey:@"strKey4"]; I get a warning: invalid receiver type 'BOOL *'
I also tried BOOL widget = [temp boolValueForKey:@"strKey4"];
I got a warning saying: 'NSDictionary' may not respond to '-boolForKey:'
BTW all the other key values are passed correctly except the BOOL.
So...flummoxed! Suggestions?
Clark,
A BOOL is just a typedef to a signed char, so it's a built-in type. For integers, doubles, floats, chars, etc. you should expect the object to be an NSNumber*. So you'd do something like this:
NSNumber* widget = [temp objectForKey:@"strKey4"];
then, you can ask the NSNumber for a bool value like so:
BOOL widgetFlag = [widget boolValue];
So, of course, you could do this in one line like this:
BOOL widget = [[temp objectForKey:@"strKey4"] boolValue];
You're getting the warning for the "boolForKey:" call because that's only for NSUserDefaults, not an NSDictionary.
Hope that helps,
Wyatt |