• 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: Translating KVO-ed property to Swift
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Translating KVO-ed property to Swift


  • Subject: Re: Translating KVO-ed property to Swift
  • From: Quincey Morris <email@hidden>
  • Date: Mon, 17 Apr 2017 01:45:03 -0700

On Apr 17, 2017, at 01:24 , Rick Mann <email@hidden> wrote:
>
> I have a number of properties in Objective-C written like this, short-circuiting notifications when the value doesn't change:

Not in this code you don’t, unless you have a “automaticallyNotifiesObserversOfVersion” method returning false elsewhere in the class. The notification doesn’t happen in the synthesized implementation of the setter, but via a swizzled replacement setter that is normally installed only when something starts observing the property. Anyway …

> Now I want to translate this method into Swift. Thing is, AFAIK you can't name the ivar created for a property. Is there a way to translate this to swift?

You do it in the “obvious” way — you declare a second, private property without a custom getter or setter, and you use this private property where you would have used the instance variable in Obj-C. The effect is the same, because the private property is optimized into just an instance variable, and the public property has no instance storage of its own (but you will have to provide a custom getter, too).

_______________________________________________

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: 
 >Translating KVO-ed property to Swift (From: Rick Mann <email@hidden>)

  • Prev by Date: Re: Translating KVO-ed property to Swift
  • Next by Date: Re: Translating KVO-ed property to Swift
  • Previous by thread: Re: Translating KVO-ed property to Swift
  • Next by thread: Re: Translating KVO-ed property to Swift
  • Index(es):
    • Date
    • Thread