• 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: Appropriateness of assign attribute and -fobj-gc-only
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Appropriateness of assign attribute and -fobj-gc-only


  • Subject: Re: Appropriateness of assign attribute and -fobj-gc-only
  • From: "Michael Ash" <email@hidden>
  • Date: Sun, 21 Sep 2008 18:02:08 -0400

On Sun, Sep 21, 2008 at 5:04 PM, Rick Mann <email@hidden> wrote:
> According to the Obj-C 2.0 docs:
>
>> assign
>> Specifies that the setter uses simple assignment. This is the default.
>>
>> If your application uses garbage collection, if you want to use assign for
>> a property whose class adopts the NSCopying protocol you should specify the
>> attribute explicitly rather than simply relying on the default—otherwise you
>> will get a compiler warning. (This is to reassure the compiler that you
>> really do want to assign the value, even though it's copyable.)
>>
>
> But the warning is:
>
> "warning: 'assign' attribute on property 'portName' which implements
> 'NSCopying' protocol not appropriate with -fobjc-gc-only"
>
> So, is it really inappropriate? It seems very appropriate to assign the
> pointer rather than allocate a new object and copy it, especially for
> immutable objects.

I'd guess that it's considered inappropriate because "assign" has the
implication that the property is a weak reference, but it will be a
strong reference under GC*. Use "retain", as it implies the correct
strong reference semantics, but when running under GC will generate a
straight-assignment setter.

* A property can be made weak by declaring its backing ivar as __weak,
but this is somewhat unusual, and in any case is not affected by the
property declaration.

Mike
_______________________________________________

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: 
 >Appropriateness of assign attribute and -fobj-gc-only (From: Rick Mann <email@hidden>)

  • Prev by Date: Re: Finding other apps' paths - deterministically!
  • Next by Date: Re: Finding other apps' paths - deterministically!
  • Previous by thread: Re: Appropriateness of assign attribute and -fobj-gc-only
  • Next by thread: How do I get CAScrollLayer to draw its sublayers
  • Index(es):
    • Date
    • Thread