• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Saving NSDictionary, Enumeration error
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: Saving NSDictionary, Enumeration error
      • From: Tamas Nagy <email@hidden>
References: 
 >Saving NSDictionary, Enumeration error (From: Tamas Nagy <email@hidden>)
 >Re: Saving NSDictionary, Enumeration error (From: Igor Elland <email@hidden>)
 >Re: Saving NSDictionary, Enumeration error (From: Tamas Nagy <email@hidden>)
 >Re: Saving NSDictionary, Enumeration error (From: Jens Alfke <email@hidden>)
 >Re: Saving NSDictionary, Enumeration error (From: Tamas Nagy <email@hidden>)

  • Prev by Date: Re: Main Window Disappears when Loaded from Separate NIB File
  • Next by Date: Does initWithHTML:dataUsingEncoding:documentAttributes: run an event loop?
  • Previous by thread: Re: Saving NSDictionary, Enumeration error
  • Next by thread: Re: Saving NSDictionary, Enumeration error
  • Index(es):
    • Date
    • Thread