Search code examples
iosobjective-cnsarraybooleannsdictionary

How to check bool value from an array of NSDictionary


I am looping through an NSArray of NSDictionaries, I am then wanting to use one of the values in the NSDictionary which is of type BOOL for an if statment.. but I am having some trouble doing this.

This is what my for loop looks like

for(NSDictionary *dict in arrayOfDictionaries)
    {
        NSNumber *boolCheck = [dict objectForKey:@"ISREADY"]; // isReady is the bool value which is either 0 or 1

        if (boolCheck == [NSNumber numberWithBool:YES]) {

//...
   }
}

What is happening is it loops through my array but never meets the condition of my if statement even though i am 100% sure there are values of this type in the array... and alot of them for that matter.

Any help would be appreciated.


Solution

  • Assuming that the NSNumber contains a BOOL, try

    if ([boolCheck boolValue]) {
        ....
    }