user367919
user367919

Reputation: 13

unable to add NSURL object to NSMutableDictionary

I am just learning objective-c but can't figure out whats wrong with my code

Code:

NSMutableDictionary *myDic = [NSDictionary dictionary];

[myDic setObject:[NSURL URLWithString:@"http://www.apple.com"] forKey:@"Apple"];

Upvotes: 0

Views: 406

Answers (1)

Eimantas
Eimantas

Reputation: 49335

Although you're declaring NSMutableDictionary you're creating immutable NSDictionary object.

The correct declaration and initialization of myDic would be

NSMutableDictionary *myDic = [NSMutableDictionary dictionary];

Upvotes: 3

Related Questions