Re: Translating KVO-ed property to Swift
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