• 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: Mutating message sent to immutable object
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: Mutating message sent to immutable object
      • From: Kyle Sluder <email@hidden>
  • Prev by Date: Re: Experience with keyed archiving forward/backwards compatibility?
  • Next by Date: Re: Mutating message sent to immutable object
  • Previous by thread: Re: Experience with keyed archiving forward/backwards compatibility?
  • Next by thread: Re: Mutating message sent to immutable object
  • Index(es):
    • Date
    • Thread