• 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: Use of assign vs. copy for accessors in Garbage Collected app
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Use of assign vs. copy for accessors in Garbage Collected app


  • Subject: Re: Use of assign vs. copy for accessors in Garbage Collected app
  • From: Shawn Erickson <email@hidden>
  • Date: Tue, 27 Nov 2007 19:51:03 -0800


On Nov 27, 2007, at 7:42 PM, Rick Hoge wrote:


Hi -

I'm experimenting with use of the @property declaration in a new app. Quite a few of my classes would be substantially simplified if this works as advertised. I'm also evaluating whether this new application would be a good candidate for Garbage Collection.

In reading the docs, a question came up regarding whether to use @property(copy) or @property(assign). In particular the following text is relevant:

assign

Specifies that simple assignment should be used in the setter. This is the default.
If you use this keyword and your application does not use garbage collection (GC), you get a compiler warning as this is rarely the correct behavior. For non-GC applications, you must explicitly specify one of the storage behavior attributes to avoid a warning for objects.


For applications that use GC, you will get a warning for this attribute if the variable adopts the NSCopying protocol as assign would typically be incorrect in that situation.


Can someone spell out for me why assign is bad in a GC app, and copy is good?

Assign isn't "bad" nor is copy "good" they just do different things and...


I would expect this would depend on the nature of the relationship between the objects being represented.

Exactly, you answered your question :)

I need to know whether there may be any hidden problems in using @property(assign) in a GC app in cases where I don't want to copy the object which is input as an instance variable.

No hidden problems as long as potential mutation of the object (assuming it is mutable) isn't an issue... OK I believe one "hidden" issues exists when an assigned mutable object is mutated KVO will not trigger for that property.


-Shawn


_______________________________________________

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: Use of assign vs. copy for accessors in Garbage Collected app
      • From: Rick Hoge <email@hidden>
References: 
 >Use of assign vs. copy for accessors in Garbage Collected app (From: Rick Hoge <email@hidden>)

  • Prev by Date: Use of assign vs. copy for accessors in Garbage Collected app
  • Next by Date: Re: Creating a color image with NSBitmapImageRep and greyscale data
  • Previous by thread: Use of assign vs. copy for accessors in Garbage Collected app
  • Next by thread: Re: Use of assign vs. copy for accessors in Garbage Collected app
  • Index(es):
    • Date
    • Thread