2

During a JSON parsing (done with AFNetwork json getter), I have this snippet of code:

if (![[data class] isKindOfClass:[NSDictionary class]]) {
    DLog(@"%@ was not kind of class NSDictionary",[data class]);
    return;
}

But for some reasons, the If sentence becomes true, and the function returns:

> __NSCFDictionary was not kind of class NSDictionary

But shouldn't __NSCFDictionary be specifically kind of class NSDictionary? or if this is the wrong way of validating, how do I do it then ?

UPDATE :

I tried turning it around, like so :

        if (![[NSDictionary class] isKindOfClass:[data class]]) {
            DLog(@"%@ was not kind of class NSDictionary",[data class]);
            return;
        }

Still doesn't work:

__NSCFDictionary was not kind of class NSDictionary

Community
  • 1
  • 1
Nils Munch
  • 8,805
  • 11
  • 51
  • 103
  • Please provide a link to `AFNetwork`. – trojanfoe Jan 24 '13 at 11:28
  • Done :) http://afnetworking.com – Nils Munch Jan 24 '13 at 11:29
  • It looks like you are getting an `__NCSFDictionary` because `AFNetworking` makes use of `NSJSONSerialization` (look at the code). There are related questions that might help you: http://stackoverflow.com/questions/7156835/what-is-an-nscfdictionary and http://stackoverflow.com/questions/13300461/how-to-get-data-thats-inside-nscfdictionary-returned-by-slrequest-on-osx – trojanfoe Jan 24 '13 at 11:47

1 Answers1

7

According to docs

isKindOfClass:
Returns a Boolean value that indicates whether the receiver is an instance of given class or an instance of any class that inherits from that class. (required)

You are using

[data class]

which will return a string.. you have to use the object/instance only i.e

if (![data isKindOfClass:[NSDictionary class]])
Shubhank
  • 21,721
  • 8
  • 65
  • 83