THObserversAndBinders icon indicating copy to clipboard operation
THObserversAndBinders copied to clipboard

THBinder returns [NSNull null] when the value is set to nil.

Open gardenrabbit opened this issue 11 years ago • 2 comments

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?

gardenrabbit avatar Dec 09 '13 06:12 gardenrabbit

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 :-)

th-in-gs avatar Dec 12 '13 14:12 th-in-gs

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.

5sw avatar Jan 28 '14 15:01 5sw