hanumanDev
hanumanDev

Reputation: 6614

How to grab a plist item based on a conditional statment?

If I'm grabbing the data in a plist using:

NSString *path = [[NSBundle mainBundle] pathForResource:@"Providers" ofType:@"plist"];
dataArray = [NSMutableArray arrayWithContentsOfFile:path];
for (NSDictionary *dictionary in dataArray)
{
    text = [dictionary valueForKey:@"text"];
    checked = [dictionary valueForKey:@"checked"];
    NSLog(@"%@ checked value is: %@", text, checked);
}

How might I go about writing a conditional statement that checks to see only if checked is set to YES and if so output the text value of the providers

Upvotes: 1

Views: 190

Answers (1)

Sergey Kalinichenko
Sergey Kalinichenko

Reputation: 726599

Assuming that checked is stored as a BOOL wrapped in NSNumber*, you can use this code:

NSNumber *checked = [dictionary valueForKey:@"checked"];
if ([checked boolValue]) {
    ...
}


* You wrap a BOOL in NSNumber by calling [NSNumber numberWithBool:myBoolValue].

Upvotes: 1

Related Questions