Hacker News new | ask | show | jobs
by skue 4577 days ago
> KVO all comes through one method

Yes, and it's annoying to have a long list of if statements. However, there's a blocks based alternative since iOS4/10.6, and a number of third-party variations.[1]

> KVO is string-ly typed

That's a big reason why libextobjc's @keypath() macro is so popular.[2]

> KVO requires you to handle superclasses yourself

That's a feature, not a bug. If you use observeValueForKeyPath:ofObject:change:context: then you need to call super just like overriding any other method. This also gives you the flexibility to selectively decide to override behavior of your own superclasses.

> KVO can crash when deregistering

Only if you deregister twice. And yes, it really sucks that you can accidentally deregister the same key path that a superclass deregisters, resulting in a crash. Much has been written about this issue, and third party libraries address it.[3]

> KVO is a pit of failure

That's a strong and subjective statement. Yes KVO can be frustrating for new developers - no argument there. But it does have its place.

> KVO is implicit

Woah, no one (including Apple) is suggesting that apps use KVO for all of their message passing and dependencies. It has its place, especially for monitoring changes to Apple's APIs or when multiple observers need to monitor the same object (again, that's a feature not a bug).

> KVO can cause infinite loops

Your handler should always avoid triggering the same event that triggered it. That's not unique to KVO.

> KVO is the old way

I remember when Apple introduced it, so I guess that makes me even older! Actually, Apple's KVO is responsible for some of the newest JS libraries. SproutCore borrowed many of KVO's ideas,[4] and you may be familiar with one of SproutCore's notable forks: Ember.js

> When is it okay to use KVO?

Agreed that these are great use cases for KVO. But doesn't this counter the title of the post? It's certainly not "harmful" to use KVO for these.

[1] https://github.com/search?l=Objective-C&q=kvo&source=cc&type...

[2] https://github.com/jspahrsummers/libextobjc/blob/master/exto...

[3] http://www.mikeash.com/pyblog/friday-qa-2012-03-02-key-value...

[4] http://guides.sproutcore.com/core_concepts_kvo.html