• 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: Fritz Anderson <email@hidden>
  • Date: Tue, 26 May 2015 12:00:28 -0500

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.

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.

	— F


_______________________________________________

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: Alex Zavatone <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>)

  • Prev by Date: Re: Custom NSView subclass - expressing the fact that a property affects the displayed image
  • Next by Date: Re: Disabling auto-synthesis of property accessors.
  • Previous by thread: Re: Disabling auto-synthesis of property accessors.
  • Next by thread: Re: Disabling auto-synthesis of property accessors.
  • Index(es):
    • Date
    • Thread