2

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?

LolaRun
  • 5,526
  • 6
  • 33
  • 45

1 Answers1

4

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?

Community
  • 1
  • 1
Matt S.
  • 1,882
  • 13
  • 17
  • yep, i already read that question, but I'm searching for a way to tell if the property is KVC without trying it by code, and seeing if it works. I suspect there's a way to detect it faster. – LolaRun Sep 03 '14 at 21:38
  • Just to clarify, KVC (Key Value Coding) and KVO (Key Value Observing) are very different things. KVC is the ability to set/get properties using the methods you are describing. KVO is the ability to observe changes to properties using the `addObserver` methods. These are all easily confused with Key Value Compliance, which refers to a property being properly set up for Key Value Observing. – KellyHuberty Nov 30 '19 at 15:01