• 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: Charles Srstka <email@hidden>
  • Date: Mon, 24 Apr 2017 18:22:10 -0500

> On Apr 24, 2017, at 1:17 PM, Quincey Morris <email@hidden> wrote:
>
> On Apr 24, 2017, at 10:11 , Charles Srstka <email@hidden <mailto:email@hidden>> wrote:
>>
>> What Quincey seemed to be referring to was a property that was not backed by any kind of persistent value.
>
> That wasn’t actually the kind of property I had in mind. I was thinking of settable, computed properties that did not depend on the value(s) of other KVO-observable properties. There probably aren’t many plausible *simple* examples, but I was thinking of such cases as when the value is stored in an I/O device rather than RAM, or when the value is retrieved from a server.

In this case, I would try to see if I could find some way to monitor changes in the underlying storage, and call the willChange and didChange methods manually when changes occur. I’d only make the property dynamic if it was completely impossible to do this, and I’d keep this to a last resort. The reason is because in this case, the property is not fully KVO-compliant, because its value can change without notifications being sent.

I did kind of touch on this with the UserDefaults-example I provided a while back. Pretending that NSUserDefaults still notified via NSNotifications only, as was the case before native KVO support was added to it, you would register for the NSNotification, check whether your default had changed, and fire the willSet and didSet notifications once it did. This is a lot more robust than depending on the automatic notifications when your property’s value may change without going through the property’s setter.

Charles

_______________________________________________

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>)
 >Re: Translating KVO-ed property to Swift (From: Jean-Daniel <email@hidden>)
 >Re: Translating KVO-ed property to Swift (From: Quincey Morris <email@hidden>)
 >Re: Translating KVO-ed property to Swift (From: Jean-Daniel <email@hidden>)
 >Re: Translating KVO-ed property to Swift (From: Charles Srstka <email@hidden>)
 >Re: Translating KVO-ed property to Swift (From: Quincey Morris <email@hidden>)
 >Re: Translating KVO-ed property to Swift (From: Charles Srstka <email@hidden>)
 >Re: Translating KVO-ed property to Swift (From: Quincey Morris <email@hidden>)
 >Re: Translating KVO-ed property to Swift (From: Charles Srstka <email@hidden>)
 >Re: Translating KVO-ed property to Swift (From: Quincey Morris <email@hidden>)
 >Re: Translating KVO-ed property to Swift (From: Charles Srstka <email@hidden>)
 >Re: Translating KVO-ed property to Swift (From: Richard Charles <email@hidden>)
 >Re: Translating KVO-ed property to Swift (From: Charles Srstka <email@hidden>)
 >Re: Translating KVO-ed property to Swift (From: Quincey Morris <email@hidden>)

  • Prev by Date: Re: iOS "library" unit test of iOS code?
  • Next by Date: Re: Help Indexing
  • Previous by thread: Re: Translating KVO-ed property to Swift
  • Next by thread: Re: Translating KVO-ed property to Swift
  • Index(es):
    • Date
    • Thread