April 2015
Intermediate to advanced
556 pages
17h 47m
English
Key-value coding (KVC) is a mechanism that allows you to get and set the value of a property indirectly using a key. A key is the name of a property as a string.
KVC has been part of Cocoa for a long time, and important features of Cocoa, like Core Data and Cocoa bindings, rely on KVC. To understand and use these technologies, it helps to understand the basics of KVC.
To experiment with KVC, create a new playground. From Xcode’s File menu, select New... → Playground. Name the playground KVC and save it with your previous exercises.
At the top of the file, define a Student class as a subclass of NSObject. Give it two variables with default values.
import Cocoa var str = "Hello, playground" class Student: ...