KVC, that is, nskeyvaluecoding, uses a name as a key to access object attributes. In essence, KVC provides an alternative to the accesser to some extent, as long as it is possible that KVC tries its best to use the accesser method.
In the key example of the returned object property, KVC searches for the return value in the following order:
1.-(<type>) getkey accessors Method
2.-(<type>) Key
3. Call valueforundefinedkey: method. The default implementation of these methods throws an exception.
4. An nsundefinedkeyexception error is thrown.
KVC can simplify the code in some cases, as shown below:
// Implementation of data-source method without key-value coding- (id)tableView:(NSTableView *)tableview objectValueForTableColumn:(id)column row:(NSInteger)row { ChildObject *child = [childrenArray objectAtIndex:row]; if ([[column identifier] isEqualToString:@"name"]) { return [child name]; } if ([[column identifier] isEqualToString:@"age"]) { return [child age]; } if ([[column identifier] isEqualToString:@"favoriteColor"]) { return [child favoriteColor]; } // And so on.}//Implementation of data-source method with key-value coding- (id)tableView:(NSTableView *)tableview objectValueForTableColumn:(id)column row:(NSInteger)row { ChildObject *child = [childrenArray objectAtIndex:row]; return [child valueForKey:[column identifier]];}