Check if NSDictionary already has a key or not
suggest changeObjective-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.
}
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents