• 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: behavior of -copy
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: behavior of -copy


  • Subject: Re: behavior of -copy
  • From: Mike Abdullah <email@hidden>
  • Date: Thu, 27 May 2010 14:18:16 +0100

On 27 May 2010, at 13:59, Ariel Feinerman wrote:

> Hi,
>
> if i understand, -copy message implement via -retain for true immutable
> objects like NSNumber, via -alloc, -init thus make true copy for mutable
> objects like NSMutableArray, my question is: what does -copy for immutable
> variant of immutable/mutable objects, for instance NSArray *arrayCopy =
> [array copy]; returns true copy or retains one? Or what does happen if
> object itself is immutable and has not setters, but it instance variables is
> mutable and can be changed?
> NSDictionary instance has NSMutableDictionary values

Container classes make shallow copies of themselves. If you've got a dictionary containing mutable dictionary values, you either:

A) NSDictionary *copy = [[NSDictionary alloc] initWithDictionary:myDict copyItems:YES];

B) Look again at your code and think that it would probably be better to create model classes rather than nested dictionaries.


>
>
> --
> best regards
> Ariel
> _______________________________________________
>
> 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

_______________________________________________

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

References: 
 >behavior of -copy (From: Ariel Feinerman <email@hidden>)

  • Prev by Date: behavior of -copy
  • Next by Date: Re: subclass overwriting superclass ivar
  • Previous by thread: behavior of -copy
  • Next by thread: Re: behavior of -copy
  • Index(es):
    • Date
    • Thread