NSDictionary - Need to check whether dictionary contains key-value pair or not
Just ask it for the objectForKey:@"b"
. If it returns nil
, no object is set at that key.
if ([xyz objectForKey:@"b"]) { NSLog(@"There's an object set for key @\"b\"!");} else { NSLog(@"No object set for key @\"b\"");}
Edit: As to your edited second question, it's simply NSUInteger mCount = [xyz count];
. Both of these answers are documented well and easily found in the NSDictionary class reference ([1] [2]).
With literal syntax you can check as follows
static const NSString* kKeyToCheck = @"yourKey"if (xyz[kKeyToCheck]) NSLog(@"Key: %@, has Value: %@", kKeyToCheck, xyz[kKeyToCheck]);else NSLog(@"Key pair do not exits for key: %@", kKeyToCheck);