Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to register KVO dependant keys at runtime in objective-c?

Tags:

objective-c

Would varying the output of +(NSSet*) keyPathsForValuesAffecting<Key> at runtime affect the dependant keys? In other words, how often/when is this method called?

like image 983
Michael Avatar asked Oct 21 '22 22:10

Michael


1 Answers

the docs give me the indication that keyPathsForValuesAffecting<Key> is only ever called when setting up the observation.

When an observer for the key is registered with an instance of the receiving class, key-value observing itself automatically observes all of the key paths for the same instance, and sends change notifications for the key to the observer when the value for any of those key paths changes.

In many cases you could probably use KVO itself to inform your observers that keyPathsForValuesAffecting<Key> has changed. manual willChangeValueForKey and didChangeValueForKey notifications for some custom key would be one way of dealing with dynamically changing keys.

like image 199
Brad Allred Avatar answered Oct 24 '22 00:10

Brad Allred