Re: Saving NSDictionary, Enumeration error
Re: Saving NSDictionary, Enumeration error
- Subject: Re: Saving NSDictionary, Enumeration error
- From: Tamas Nagy <email@hidden>
- Date: Wed, 08 May 2013 07:13:46 +0200
Hmm, yes, its possible saveData method returns an NSDictionary which contains NSMutableDictionaries if I missed something in my code. Thanks, I'll check it out.
On May 8, 2013, at 12:13 AM, Jens Alfke <email@hidden> wrote:
>
> 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