Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

Share this Page URL
Help

Chapter 11. Key-Value Coding > Ensuring KVC Compliance - Pg. 197

Ensuring KVC Compliance use -setValue:forKey: . This method is implemented by NSObject . It will fail at run time when you call it on an immutable dictionary, but there will be no hint of this at compile time. The other big difference is the use of nil . If you use nil as the value with -setValue:forKey: , it will delete that key. If you do the same for -setObject:forKey: , you get an exception. 197 Ensuring KVC Compliance 3 4 5 6 7 8 9 10 11 @interface KeyPublic : NSObject @end @implementation KeyPublic @end @interface KeyIVar : KeyPublic { int integer; } @end @implementation KeyIVar @end From: kvc.m When you use the KVC methods, you almost always call the implementations in NSObject . These then try to work out how the property should really be accessed. The first place they will look is at accessor methods. By convention, Objective-C classes provide -property and -setProperty: methods for reading and setting the "property." If your class provides these, they will be called. KVC