tags:

views:

59

answers:

3

Okay I am completely noob on C++ or Objective C++.

Here is my question.

There is .plist file that has a key say XYZ and the value can be on or off.

Now I have this method ...BOOL isEnabled().

I want to check the value for that in that plist and return BOOL based on on or off.

How do I do that?

NSDictionary *plistDict = [NSDictionary dictionaryWithContentsOfFile:@"/var/mobile/Library/Preferences/com.apple.BTServer.airplane.plist"];
BOOL Location = [[plistDict objectForKey:@"airplaneMode"] boolValue];

return Location;

This code is for Location Toggle for iPhone/SBSettings. Here for Location toggle the values are stored as 1 and 0 but for Airplane mode for which I modifying this code the values are on/off.

How do I convert on /off to BOOL?

Thank you

A: 

Is the on/off encoded as a string? If so, how about a string comparison?

NSString *strLocation = [[plistDict objectForKey:@"airplaneMode"] lowercaseString];
if ([strLocation isEqualToString:@"on"])
{
   return TRUE;
}
return FALSE;
No one in particular
With the risk of being pendantic, even though TRUE / FALSE are defined, the canonical values for BOOL types are YES / NO.
Julio Gorgé
A: 

Yo probably want to use something like this to store a BOOL value on a dictionary/plist:

[myDictionary setObject:[NSNumber numberWithBool:YES]] 

Though you'd use YES or NO depending on the value of the integer you want to store.

Julio Gorgé
A: 

Or you can do a one-line if statement like so:

BOOL location = ([[plistDict objectForKey:@"airplaneMode"] isEqualToString:@"On"]) ? YES : NO;
MishieMoo
`YES` and `NO` are the common identifiers associated with the `BOOL` type.
dreamlax
TRUE, FALSE, 0 and 1 also work though, and some people understand it better.
MishieMoo