-2

Why does the following code returns not a NSDictionary, but a __NSDictionaryI?

NSDictionary* dict = [NSDictionary dictionary];
Class c = [dict class];
NSLog(@"%@", c);

What are my options to check if an object is an instance of NSDictionary? As I've found out, I can't call [__NSDictionaryI class] because it's not visible.

[dict classForCoder] returns NSDictionary and seems to be a good solution, but won't it fail when calling on object of some custom class? What is the most universal method to check if an object is an instance of a given class?

Yury Pogrebnyak
  • 4,093
  • 9
  • 45
  • 78

2 Answers2

2

According to header that can be found here __NSDictionaryI is descendant of NSDictionary, so I guess you can use this check:

NSDictionary* dict = [NSDictionary dictionary];
if ([dict isKindOfClass:[NSDictionary class]])
{
//your code here
}

and it should work with NSDictionary and __NSDictionaryI instances.

Bohdan Ivanov
  • 806
  • 9
  • 28
1

How to check a class in a NSDictionary

if([object isKindOfClass:[AObjectClass class])
{
    NSLog(@"object is of type AObjectClass");
}
Community
  • 1
  • 1
pckill
  • 3,709
  • 36
  • 48