first, KVC and Kvo
* "KVC": Key value Coding (key code) * Objective: To indirectly modify or get the properties of the object, reducing the coupling between the program (class and Class).
* "KVO": Key value Observer (observed by the keys), observer mode. * Purpose: Often used to observe a change in a property of an object in time to make a corresponding.
second, the use of the way KVC
KVC is called the iOS development platform's big recruit!!! Can quickly modify object properties. *[p1setvalue:@ "xxxx" forkeypath:@ "name"; Modify the specified object properties. *[arrvalueforkeypath:@ "Book.bookname"]; Gets the object property. *KVC can get the array directly through the key. * When using KVC, be sure to ensure that the key value exists. * Principle: When a value is KVC, if the object is found to not contain the specified key value, it automatically goes to the inner member of the object to find it.
third, the use of KVO
*KVO is often used to observe the change in an object's properties and react accordingly. (much used to observe model data) a distinction between *KVO and notification centers: KVO can only stare at an object (working within the current area), and the notification Center can traverse many layers (such as Viewcontroller). *kvo use steps: *1. [stuaddobserver:selfforkeypath:@ ' Name ' options:nskeyvalueobservingoptionnew | Nskeyvalueobservingoptionold context:@ "Myobserver"]; *2.observevalueforkeypath. This method is automatically invoked when the specified key value changes *3.removeobserver. All observer modes have poor performance and need to be removed in a timely manner.
Directly on the code:[OBJC] View plain copy// // xnviewcontroller.m //  KVC----KVO // // created by neng on 14-6-21. // copyright (c) 2014 year neng. All rights reserved. // #import "XNViewController.h" #import "XNPerson.h" #import XNStudent.h " #import " XNBook.h " @interface XNViewController ( ) @end /** * kvc: key value coding (key value code * indirectly modify/Get the object's properties, reduce the coupling between classes and classes . * kvo: key value observer (Key-value observation)    KVO are often used to observe a change in the "object's properties" and respond in a timely manner. Nsnotificationcenter is an object that requires the post "notification string" (which indicates the type of event being monitored) to be present, and the notification Center can work. */ @implementation xnviewcontroller - (void) viewdidload { [ super viewdidload]; //1. Simple Modify Object Properties [ self kvcdemo1];     //2. For subclass, can also directly modify [self kvcDemo2];     //3. Modify the book property of an object . (rather troublesome, to create a book object). KVC word [self kvcDemo3]; //4. Gets the property value of the object . can be obtained in batches (if it is an array) . [self kvcDemo4]; //KVO Demo [self kvoDemo]; }