Fasid
Fasid

Reputation: 255

Is it ok to cast a NSdictionary object to NSMutableDictionary?

Is it ok to cast a NSdictionary object to NSMutableDictionary?

NSDictionary *dict;
NSMutableDictionary *mDict = (NSMutableDictionary *)dict;

Tried this and it worked fine.

Upvotes: 0

Views: 2634

Answers (1)

jer
jer

Reputation: 20236

No it is not. If you want a mutable dictionary, make one:

NSMutableDictionary* mutableDict = [dict mutableCopy];

Do not forget in accordance with the rules you own mutableDict and must release it when you are done with it.

Upvotes: 6

Related Questions