• 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: Tamas Nagy <email@hidden>
  • Date: Tue, 07 May 2013 23:32:00 +0200

Okay, maybe I misunderstood something, but since I collect the data to an NSMutableDictionary, then turn it to a non-mutable NSDictionary, like this:

-(NSDictionary)saveData {
NSMutableDictionary *dict = [[[NSMutableDictionary alloc] init] autorelease]
[dict setObject:...]
return NSDictionary dictionaryWithDictionary: [[dict copy] autorelease]];

so does not this made the dictionary already read-only?

On May 7, 2013, at 8:06 PM, Jens Alfke <email@hidden> wrote:

>
> On May 7, 2013, at 7:04 AM, Tamas Nagy <email@hidden> wrote:
>
>> The data collecting and save happening on the main thread, but the objects providing the data may run on an other - rendering - thread. Maybe its a problem with an object while collecting the save data, and I forgot about copy the value?
>
> Copying the value isn't enough! Foundation collections are not thread-safe — you shouldn't access a dictionary (or array or set or string) on one thread while modifying it on another. The only safe way to share these objects is read-only. (There's a whole document in Apple's doc-set about the thread-safety of various Cocoa classes. In general, never assume a class is thread-safe unless the docs explicitly say so.)
>
> In this specific crash, the presence of "__NSFastEnumerationMutationHandler" in the exception backtrace shows that the enumerator detected that the dictionary had been modified during the enumeration, which is illegal (even on a single thread.)
>
> —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: Jens Alfke <email@hidden>
    • Re: Saving NSDictionary, Enumeration error
      • From: Scott Ribe <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>)

  • Prev by Date: Re: Showing numpad key equivs in menu items
  • Next by Date: Re: Saving NSDictionary, Enumeration error
  • Previous by thread: Re: Saving NSDictionary, Enumeration error
  • Next by thread: Re: Saving NSDictionary, Enumeration error
  • Index(es):
    • Date
    • Thread