Re: BOOL value in Dictionary
Re: BOOL value in Dictionary
- Subject: Re: BOOL value in Dictionary
- From: Graham Cox <email@hidden>
- Date: Sat, 22 Nov 2008 01:15:58 +1100
On 22 Nov 2008, at 12:48 am, Richard S. French wrote:
How does one get a boolean value from a dictionary object?
My XML dictionary contains the value </true> under the given key.
Should this be retrieved as NSNumber or some other object?
Yes, that's right.
I am trying to set the state of a checkbox button based on the value
as
below:
// return syntax coloring switch
BOOL *colorSwitch = NO;
colorSwitch = [NSNumber numberWithBOOL:[temp
objectForKey:@"BBLMColorsSyntax"]];
NSLog(@"Color: %@", colorSwitch);
if ( colorSwitch == YES) {
[colorBox setState:NSOnState];
}
else {
[colorBox setState:NSOffState];
}
Unfortunately, this is just wrong.
BOOL is a scalar type, not an object. BOOL* is a pointer to a BOOL -
such a thing is almost never used.
NSNumber is an object, so NSNumber* is your object reference.
So either you want:
BOOL colourSwitch = [[temp objectForKey:@"blah"] boolValue];
or
NSNumber* colourSwitch = [temp objectForKey:@"blah"];
BOOL csBool = [colourSwitch boolValue];
Tip:
option-double-click stuff to reveal it in the documentation, command-
double-click to reveal it in the headers. That will save you a ton of
grief.
hth,
Graham
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden