LolaRun
LolaRun

Reputation: 5666

How to know if a class is KVO compliant for a certain property?

I want to use KVO on a property say for UIView, but i don't know if it is compliant. take for example "hidden" property.

I went to the header file of the UIView class, and couldn't find an indication, and i also went to the documentation of this property. Someone talked about 'checking the references for compliancy' what references is he talking about?

Upvotes: 3

Views: 3075

Answers (1)

Matt S.
Matt S.

Reputation: 1892

It sounds like they're referring (rather vaguely) to the KVC Compliance documentation here:

https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/KeyValueCoding/Articles/Compliant.html#//apple_ref/doc/uid/20002172

Specifically, you need to see if the class responds to valueForKey: and setValue:forKey: for a given key. The documentation is rather spare on how you should actually check for compliance. My first thought is wrap your code in a try/catch block, and catch the exception, but that probably won't work given how that exception is generally thrown.

The general assumption is most objects in UIKit are NOT KVO compliant, and if you need them to be, you can subclass and implement it. You can see a very similar question / duplicate here, with an answer from Dave Delong, the Apple Frameworks Evangelist:iOS: How do I know if a property is KVO-compliant?

Upvotes: 5

Related Questions