I am learning about Key-Value coding in Chapter 7 of "Cocoa(R) Programming for Mac(R) OS X (3rd Edition)".
I would say the most important lesson from this chapter is knowing what accessor methods are and when they get called. The author's tutorial in this chapter clearly demonstrates this behavior. In the tutorial, I implemented an AppController with two accessor methods "set" and "get".
The implementation of these methods were fundamentally simply.
"set" sets an instance variable in the AppController class to a specified value
"get" returns that value
The "set" accessor method got called when I used "setValue ... forKey".
e.g. [self setValue:[NSNumber numberWithInt:5] forKey:@"fido"];
The "get" accessor method got called when I used "valueForKey".
e.g. NSNumber *n = [self valueForKey:@"fido"];
The tutorial helped illustrate this by having me issue NSLog calls from within each accessor method. I was also taught how to bind key-value code to a graphical object, in this case a slider. When the slider moved, the NSLog calls showed the set and get methods being called in the GDB debug console window.
-
No comments:
Post a Comment