开发者

How do you get a list of observable keypaths for KVO?

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜