Amogh Talpallikar
Amogh Talpallikar

Reputation: 12184

Strange behavior reading Dictionary from a plist file

When I read a plist for a dictionary which is not empty and has at-least one key value pair into an NSMutableDictionary property of my model class, Everything works fine. I can add,delete modify the mutable dictionary.

But when the dictionary is empty

and you can see the plist with a tag like this :

<dict/>

Then, even though my property has an NSMutableDictionary pointer, Object which is created becomes immutable.

and when I try to set an object in it for a particular property, It gives me this error saying:

'NSInternalInconsistencyException', reason: '-[__NSCFDictionary setObject:forKey:]: mutating method sent to immutable object'

Upvotes: 1

Views: 228

Answers (2)

nielsbot
nielsbot

Reputation: 16022

Pretty sure all objects retrieved from a plist are the immutable variants. I do think I saw an option to deserialize them as mutable however.

Edit:

this article explains how to unarchive a plist as mutable:

http://cocoadev.com/wiki/PropertyList

Upvotes: 1

Michael Robinson
Michael Robinson

Reputation: 29498

NSMutableDictionary *mutable = [yourApparentlyMutableDictionary mutableCopy];

Upvotes: 2

Related Questions