Checking a boolean value from a dictionary.

I have a variable called “pull” from a JSON feed. After checking the type of the class, the object is interpreted as NSLog this:

attending var type is: __NSCFBoolean

This is done using [varname class] to get the class type of the variable.

So, I want to see if this is true or false .... therefore I am writing this code ..:

if([[_events objectAtIndex:indexPath.row] objectForKey:@"attending"] == YES){

However, I cannot compile it because it gives me a yellow text error:

enter image description here

What am I doing wrong? How can I fix this. Just adding data to the feed is as follows:

    {
    attendees =         (
    );
    attending = 1;
    date = "2012-09-24 09:11:00";
    id = 504;
    lessonHTML = "somehtml.";
    name = "Sup";
    youtubeId = "http://www.youtube.com/watch?v=j1vb4cND3G0";
},
    {
    attendees =         (
    );
    attending = 1;
    date = "2012-09-24 09:11:00";
    id = 503;
    lessonHTML = "somehtml.";
    name = "Sup";
    youtubeId = "http://www.youtube.com/watch?v=j1vb4cND3G0";
},
    {
    attendees =         (
    );
    attending = 0;
    date = "2012-09-24 09:11:00";
    id = 508;
    lessonHTML = "somehtml.";
    name = "Sup";
    youtubeId = "http://www.youtube.com/watch?v=j1vb4cND3G0";
},
    {
    attendees =         (
    );
    attending = 1;
    date = "2012-09-24 09:11:00";
    id = 509;
    lessonHTML = "somehtml.";
    name = "Sup";
    youtubeId = "http://www.youtube.com/watch?v=j1vb4cND3G0";
},
    {
    attendees =         (
    );
    attending = 0;
    date = "2012-09-24 09:11:00";
    id = 505;
    lessonHTML = "somehtml.";
    name = "Sup";
    youtubeId = "http://www.youtube.com/watch?v=j1vb4cND3G0";
},
    {
    attendees =         (
    );
    attending = 1;
    date = "2012-09-24 09:11:00";
    id = 506;
    lessonHTML = "somehtml.";
    name = "Sup";
    youtubeId = "http://www.youtube.com/watch?v=j1vb4cND3G0";
},
+5
source share
2 answers

Logical dictionary and other container classes are encapsulated in objects NSNumber(see documentation for more information NSNumber)

, boolValue , , YES/NO:

NSNumber* attendingObject = [[events objectAtIndex:indexPath.row] objectForKey:@"attending"];
if ([attendingObject boolValue] == YES)
{
    ...
}

, . Apple

+18

a "BOOL" Objective C, C.

"NSNumber".

, , :

if([[_events objectAtIndex:indexPath.row] objectForKey:@"attending"] == YES){

:

BOOL attending = NO; // assume NO to start with
NSDictionary * lessonDictionary = [_events objectAtIndex: indexPath.row];
if(lessonDictionary)
{
     NSNumber * attendingObject = [lessonDictionary objectForKey: @"attending"];
     if(attendingObject)
     {
          attending = [attendingObject boolValue];
     }
}
+2

All Articles