Wednesday, June 19, 2013

NSMutableDictionary setValue example in Objective C (iOS).

NSMutableDictionary setValue

Adds a given key-value pair to the dictionary.

- (void)setValue:(id)value forKey:(NSString *)key

Parameters of [NSMutableDictionary setValue]
The value for key.
The key for value. Note that when using key-value coding, the key must be a string (see “Key-Value Coding Fundamentals”).

Discussion of [NSMutableDictionary setValue]
This method adds value and key to the dictionary using setObject:forKey:, unless value is nil in which case the method instead attempts to remove key using removeObjectForKey:.

NSMutableDictionary setValue example.
NSMutableDictionary *parameters = [[NSMutableDictionary alloc] init];
[parameters setValue:[NSNumber numberWithBool:news] forKey:@"news"];
[parameters setValue:[NSNumber numberWithBool:mails] forKey:@"mails"];

End of NSMutableDictionary setValue example article.