How do you get a list of observed key paths for KVO?

If I have some instance of the class, say UIView or its subclass or just a simple subclass of NSObject, how can I get a list of observed key paths of this object?

I would like to get a list of valid keyPath values ​​for the object that will be used in the addObserver method.

+3
source share
1 answer

You cannot get a complete list of kvo-compatible keys for an object. Such a list does not exist. An object can not only use any keys it needs, but it can even dynamically add new keys at run time. The best thing you can probably do is iterate over all the properties, treat their names as keys, and perhaps iterate over methods that look for something from the form -setFoo:to handle "foo" as the key. But this is not perfect, and he does not guarantee that everyone will be caught.

+3
source

Source: https://habr.com/ru/post/1778844/


All Articles