Possible Duplicate:
How to add to an NSDictionary
When I do that :
NSDictionary *dic = [NSDictionary dictionary];
[dic setValue:@"nvjd" forKey:@"name"];
my app just crash. I don't understand why. How should I add a string in a dictionary ?
You need to make your dictionary mutable, otherwise it would not respond to the setValue:forKey:
selector:
NSMutableDictionary *dic = [NSMutableDictionary dictionary];
This is a common pattern in cocoa: you often see classes declared in pairs: NSArray
/NSMutableArray
, NSSet
/NSMutableSet
, NSString
/NSMutableString
, and so on. Mutable version is capable of doing everything that the immutable version can do, but it also supports operations that change its content.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With