Learn moreCocoaMediumKVOWhat is the mechanism that will be introduced in this article? through this article, you can learn it easily.CocoaLet's take a look at the details.
The most basic thing about iPhone development is to master AppleCocoaThis basic framework of object-oriented development is briefly introduced in this article.CocoaOfKVOThe concept and usage of the mechanism.
Q: What kind of Cocoa mechanism is KVO?
A: KvoKey Value Coding is the protocol used to set values or values in cocoa (NSKeyValueCoding), which is similar to java's ejb. Both variables and function names are standardized to facilitate the setting of class member values. it is an important mechanism of Cocoa. It is a bit similar to Notification, but it provides a way to observe the changes of a certain attribute, and Notification requires an object to send notification, in this way, KVO greatly simplifies the code than Notification. This observation-the observed model applies to such situations. For example, A property in B (view class) changes accordingly based on A property value change in A (data class. For cocoa, which advocates MVC, kvo has a high application value.
Kvo usage:
1. Registration:-(void) addObserver :( NSObject *) anObserver forKeyPath :( NSString *) keyPath options :( NSKeyValueObservingOptions) options context :( void *) context keyPath is the attribute value to be observed, options allows you to observe the selection of key value changes, while context facilitates the transmission of the data you need (note that this is a void type)
2. Implementation Methods:
-(Void) observeValueForKeyPath :( NSString *) keyPath ofObject :( id) object change :( NSDictionary *) change context :( void *) context change stores changed data, for example, the data before the change and the data after the change. If the context is not empty during registration, the context can be received here. Is it easy? The kvo logic is very clear and the implementation steps are simple.
Summary: Learn MoreCocoaMediumKVOAfter the introduction of the mechanism, whether or notKVOHave a basic understanding. Okay! Finally, I hope this article will help you!