-1

I have seen answers aleready posted, they all are talking about... using objectForKey method on NSDictionary, which is not proper if we dont know the key's.

Leo
  • 24,596
  • 11
  • 71
  • 92
Vinod Supnekar
  • 143
  • 1
  • 7

2 Answers2

3

You can use the count property to test if a NSDictionary has any entries.

if (aDic.count == 0) {
    // aDic is empty.
} else {
    // aDic has some entries.
}

And, you can use the objectForKey: method to test if a specific entry exist.

For example, I want to know if a key named "foo" exist in the dictionary:

if ([aDic objectForKey:@"foo"] != nil) {
    // aDic has a entry named "foo"
} else {
    // "foo" doesn't exsits
}

Also, you can simplify this:

if (aDic[@"foo"]) {
    // aDic has a entry named "foo"
} else {
    // "foo" doesn't exsits
}
liushuaikobe
  • 2,152
  • 1
  • 23
  • 26
-2
if ([yourDictionary isKindOfClass:[NSDictionary class]])
{
    NSLog(@"%@",yourDictionary)
}
fedorqui
  • 275,237
  • 103
  • 548
  • 598
Mohak
  • 44
  • 1
  • 6