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 11:06:50 -0700
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