Search code examples
iosobjective-cnsdictionarykey-value-coding

What's the difference between Key-Value Coding and NSDictionary?


What's the difference between Key-Value Coding and NSDictionary? KVC has addValue:forKey and NSDicationary has addObject:forKey, which gives me the impression that they're very similar structures.


Solution

  • Key Value Coding is a set of conventions for accessing the contents of an object using string identifiers. KVC compliant classes have properties that follow the KVC naming convention. A number of different technologies are layered on top of KVC and depend on it to function. KVC is implemented as an informal protocol on NSObject. KVC can can be used with all descendants of NSObject, as long as the object's properties are compliant with the KVC naming conventions.

    NSDictionary, in contrast, is a Foundation collection class representing a class cluster.

    KVC is a fundamental concept in Cocoa, the more you know about it the better your applications will be.