Re: Mutating message sent to immutable object
Re: Mutating message sent to immutable object
- Subject: Re: Mutating message sent to immutable object
- From: Greg Parker <email@hidden>
- Date: Sun, 01 Sep 2013 13:41:13 -0700
On Aug 31, 2013, at 7:10 PM, Gerriet M. Denkmann <email@hidden> wrote:
> 2. Why did this even occasionally work before I made my veryDeepMutableCopy?
> NSUserDefaults tells me about dictionaryForKey: "The returned dictionary and its contents are immutable, even if the values you originally set were mutable."
>
> Does this really mean: "The returned dictionary and its contents are mutable or immutable depending on our whims. You better not rely on their mutability state."
You're not entirely left up to their whim. A return value whose declared type is immutable imposes restrictions on both sides:
1. You must not mutate the returned object.
2. The returned object will not be mutated behind your back by anyone else.
These are both true even if the object actually returned is a mutable one.
--
Greg Parker email@hidden Runtime Wrangler
_______________________________________________
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