O'Reilly logo

Cocoa Programming for OS X: The Big Nerd Ranch Guide by Aaron Hillegass, Adam Preble, Nate Chandler

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

8 KVC, KVO, and Bindings

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.

i​m​p​o​r​t​ ​C​o​c​o​a​ v​a​r​ ​s​t​r​ ​=​ ​"​H​e​l​l​o​,​ ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required