Re: Saving NSDictionary, Enumeration error
Re: Saving NSDictionary, Enumeration error
- Subject: Re: Saving NSDictionary, Enumeration error
- From: Jens Alfke <email@hidden>
- Date: Tue, 07 May 2013 15:13:19 -0700
On May 7, 2013, at 2:32 PM, Tamas Nagy <email@hidden> wrote:
> -(NSDictionary)saveData {
> NSMutableDictionary *dict = [[[NSMutableDictionary alloc] init] autorelease]
> [dict setObject:...]
> return NSDictionary dictionaryWithDictionary: [[dict copy] autorelease]];
This does indeed create a new immutable dictionary object to return. (Although the last line is doing too much work; -dictionaryWithDictionary: does the same thing as -copy.)
However, are you sure the value objects in the dictionary are immutable too? Copying is not deep — when you copy a container, the objects stored in the container are merely retained, not copied too. So if you use that dictionary returned from -saveData on another thread, you're probably using the objects stored in it in multithreaded ways.
I don't have your original message handy anymore, but IIRC the backtrace was a few levels deep in nested enumerations, which makes me think that the mutation exception is happening to a nested dictionary, not the outer one.
—Jens
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden