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 14:04:45 -0700
On Apr 17, 2017, at 12:03 , Charles Srstka <email@hidden> wrote:
>
> You cannot guarantee that the property will be called via objc_msgSend, which is important if you’re relying on the swizzled accessor to send the property notifications. If you’re sending them yourself, it doesn’t matter one way or another how the property was called, as long as you add @objc so that clients that do expect to be able to use objc_msgSend (most importantly, NSObject’s observation support) can do it.
If you’re sending them yourself, then what matters is that you don’t *accidentally* let the property generate automatic notifications as well. There is only one way (AFAIK) to *guarantee* that automatic notifications aren’t generated as well, and that’s by returning false from ‘automaticallyNotifiesObserversOfVersion’. There’s no other way in Swift (AFAIK) to ensure that, since there’s no “nondynamic” keyword. There’s also no other way in Obj-C (AFAIK) to ensure that.
This issue wasn’t supposed to be about Swift, though Swift makes it a bit murkier. Rick’s original code was wrong unless he had an Obj-C automaticallyNotifiesObserversOfVersion method elsewhere. For all I know, since he didn’t weigh back in with more information, he had that method all along.
> You also forgot the automaticallyNotifiesObserversOfVersion property in the first bit of my example.
Yes, sorry, I just didn’t see it tucked up against the comment. Your code was correct in every detail.
_______________________________________________
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