Check if NSDictionary already has a key or not

suggest change

Objective-C:

// Objects and keys alternate: object, key, object, key, nil.
NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:@"Sam", @"name1", @"Sanju", @"name2", nil];

// Check whether the dictionary contains the key you are going to modify.
if (dict[@"name1"] != nil) {
    // There is an entry for key name1.
}
else {
    // There is no entry for name1.
}

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents