On Jan 18, 2015, at 2:45 PM, Trygve Inda <cocoa...@xericdesign.com> wrote:

> So is this safe...
> 
> NSMutableDictionary* collection;  // keys are myID, values are MyObject
> 
> for (MyObject* object in [[self collection] allValues])
> {
>    [collection removeObjectForKey:[object myID]];
> }
> 
> It would seem that this is really enumberating the allValues array which
> assuming it is only called once, represents the objects that exist at the
> beginning of the for loop and removing them fro the collection dictionary is
> safe.

It is probably safe.  It is very improbable that the -allValues method will 
return a reference to an internal mutable array used by NSMutableDictionary and 
therefore modified if you mutate it.  It is very improbable that 
NSMutableDictionary uses any such mutable array internally.

The fact that the modern declaration of allValue is as a declared property with 
the "copy" attribute is also a suggestion that it would be safe.

However, none of this is a guarantee that it's safe.  If you want to be 
certain, you can use [[self.collection.allValues copy] autorelease] (omit the 
autorelease under ARC).

Regards,
Ken


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to