• 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: Disabling auto-synthesis of property accessors.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Disabling auto-synthesis of property accessors.


  • Subject: Re: Disabling auto-synthesis of property accessors.
  • From: Alex Zavatone <email@hidden>
  • Date: Tue, 26 May 2015 13:24:08 -0400

On May 26, 2015, at 1:00 PM, Fritz Anderson wrote:

>
> On 22 May 2015, at 7:49 AM, Alex Zavatone <email@hidden> wrote:
>
>> @property (nonatomic, strong) NSString *thing;
>>
>
> Another chore in porting this code: The retention attribute should be copy, not strong.

I just typed that off the top of my head, BUT now that you mention it, I'm really happy you pointed it out.

For any nonmutable class, should I be using copy instead of strong or is this just with NSString?


> If you needed to track changes in the string, you'd use strong, but NSStrings don’t mutate; NSMutableStrings do.
>
> If you do assign a mutable string into the NSString property, the non-mutable class promises the users of your API that it won’t mutate. You need a copy to prevent changes behind your back. The performance hit is the price you pay to prevent a bug.
>
> copy is not a performance issue for NSString. It doesn’t copy anything, it just increments the retain count and returns the same pointer. (Static/global NSStrings don’t even bother to deallocate themselves.) Copying a mutable string does allocate and initialize a new object; either way, the attribute does the Right Thing.
>

Thanks.  This is stuff that my brain didn't have room for when deciphering what our classes were actually doing.

Best,
Alex Zavatone
_______________________________________________

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: Disabling auto-synthesis of property accessors.
      • From: Uli Kusterer <email@hidden>
    • Re: Disabling auto-synthesis of property accessors.
      • From: Jens Alfke <email@hidden>
References: 
 >Disabling auto-synthesis of property accessors. (From: Alex Zavatone <email@hidden>)
 >Re: Disabling auto-synthesis of property accessors. (From: Kyle Sluder <email@hidden>)
 >Re: Disabling auto-synthesis of property accessors. (From: Fritz Anderson <email@hidden>)
 >Re: Disabling auto-synthesis of property accessors. (From: Quincey Morris <email@hidden>)
 >Re: Disabling auto-synthesis of property accessors. (From: Uli Kusterer <email@hidden>)
 >Re: Disabling auto-synthesis of property accessors. (From: Alex Zavatone <email@hidden>)
 >Re: Disabling auto-synthesis of property accessors. (From: Alex Zavatone <email@hidden>)
 >Re: Disabling auto-synthesis of property accessors. (From: Fritz Anderson <email@hidden>)

  • Prev by Date: Re: Disabling auto-synthesis of property accessors.
  • Next by Date: Off center guides
  • Previous by thread: Re: Disabling auto-synthesis of property accessors.
  • Next by thread: Re: Disabling auto-synthesis of property accessors.
  • Index(es):
    • Date
    • Thread