Retrieve ValueForKey BOOL value

ios, key-value

Solution

BOOL active = [[apIndicators[i] valueForKey:@"isActive"] boolValue];

if (active){
    // do whatever
}

If those apIndicators are all NSDictionaries you could use the fast enumerator to simplify the loop quite a bit as well.

for (NSDictionary *apIndicator in yourArray){
    BOOL active = [[apIndicator valueForKey:@"isActive"] boolValue];
    if (active){
        // do whatever
    }
}

Problem

I mark some objects as inactive ``` [apIndicators[i] setValue:[NSNumber numberWithBool:NO] forKey:@"isActive"]; ``` Later I set some of them as active. Then I have to check all inactive objects left in 'NSMutableArray'. I have to do that in for loop ``` for (int i = 0; i < apCount; i++) { if [apIndicators[i] valueForKey:@"isActive"]) { //the problem is here //do some stuff with object } } ``` How can I get YES or NO value of every object in array? Thanks in advance.

Original source