iOS 11 Screencasts: What's New in Foundation - | Ray Wenderlich

Foundation now gives a new way to interact with KVO by way of new keypaths and the addition of observers.


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/4056-what-s-new-in-foundation-key-value-observing-kvo

Hi Ryan,

At first, thank you for simple explanation about KVO.

I’ve just downlaoded the example and It did’t pass that observation closure until I added the NSKeyValueObservingOptions new and old. Why it wouldn’t work? May I miss something important?

Example Code that I wrote:

//this will work because I added options đź‘Ť
token = NewsAPI.service.observe(\.sources, options: [.old,.new], changeHandler: { (newsApi, value) in
    DispatchQueue.main.async {
        self.tableView.reloadData()
    }
})

//This is not working🤔
token = NewsAPI.service.observe(\.sources) { _, _ in
    DispatchQueue.main.async {
      self.tableView.reloadData()
    }
}

Hey There, what compile error are you receiving for the code that isn’t working?

Hi,

I didn’t see any compile error. But It works your next screencast :] I got the main point of view and its enough actually :] Again, thanks for your interest.

1 Like

I’m glad to hear everything is resolved. Let me know if you run into any other issues.

I encountered a few nil values when decoding. If anyone else counters that, try making the vars in the structs optional and wrapping the the vars in if-let statements when they’re called.

1 Like

This topic was automatically closed after 166 days. New replies are no longer allowed.