If I have some instance of a class, say a UIView or 开发者_运维问答subclass of it or just a simple subclass of NSObject, how can I get a list of the observable keypaths of that object?
I'd like to get a list of the valid keyPath values for the object to use them in the addObserver method.
You cannot get a full list of kvo-compatible keys for an object. No such list exists. Not only is the object free to use whatever keys it wants, but it can even dynamically add new keys at runtime. The best you're likely to be able to do is to iterate over all the properties, treat their names as keys, and perhaps iterate over methods looking for anything of the form -setFoo:
to treat "foo" as a key. But this is not foolproof, and it's not guaranteed to catch everything.
精彩评论