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()
}
}
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.
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.