THObserversAndBinders
THObserversAndBinders copied to clipboard
THBinder returns [NSNull null] when the value is set to nil.
I just added lines of code in "changeBlock" to set the value to nil if new value in the change dictionary is null class. Is there a better way?
You mean in your own change block? Yes, that's the correct thing to do.
You bring up a good point though - I'm not doing anything to massage what KVO supplies in its changeDictionary before passing it to 'clients' of the APIs. I think you might be right in your assumption that NSNull being converted to nil would be less surprising than passing it through as-is. I will think about that (suggestions or arguments welcome here :-)
I often find crashes where unsupported messages are sent to NSNull. Basically I have to repeat the check for NSNull in the transformationBlock of every binder I use. IMHO all this repeated code is a sure sign that the THBinder should do that translation itself.
Also I can't imagine any use case where one would actually want to receive the NSNull since with KVO one never can distinguish between the case where a property is set to nil or NSNull. And that means that THBinder can't be used anyways where such a distinction is important.