Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retrieve ValueForKey BOOL value

Tags:

ios

key-value

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.

like image 304
Palindrome Avatar asked Dec 15 '22 02:12

Palindrome


1 Answers

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
    }
}
like image 166
T. Benjamin Larsen Avatar answered Jan 08 '23 00:01

T. Benjamin Larsen