Name
NSKeyValueCoding — Mac OS X 10.0
Synopsis
This informal protocol provides a way for clients to access a
class’s instance variables (or other properties)
without having to explicitly rely on accessor methods.
NSKeyValueCoding
provides indirect access to an
object’s instance variables through the use of
strings or keys. The two most commonly used methods in the protocol
are takeValue:forKey
: and
valueForKey
:, which are used to set and get the
value of an instance variable, respectively. This protocol, and the
associated NSScriptKeyValueCoding
protocol, both
form the basis of scripting in Cocoa. Chapter 2
goes into more detail about this protocol.
@interface NSObject (NSKeyValueCoding)
|
// Class Methods
|
+ (BOOL)accessInstanceVariablesDirectly;
|
+ (BOOL)useStoredAccessor;
|
// Instance Methods
|
- (id)valueForKey:(NSString *)key; |
- (void)takeValue:(id)value forKey:(NSString *)key; |
- (id)storedValueForKey:(NSString *)key; |
- (void)takeStoredValue:(id)value forKey:(NSString *)key; |
- (id)valueForKeyPath:(NSString *)key; |
- (void)takeValue:(id)value forKeyPath:(NSString *)key; |
- (NSDictionary *)valuesForKeys:(NSArray *)keys; |
- (void)takeValuesFromDictionary:(NSDictionary *)dictionary; |
- (id)handleQueryWithUnboundKey:(NSString *)key; |
- (void)handleTakeValue:(id)value forUnboundKey:(NSString *)key; |
- (void)unableToSetNilForKey:(NSString *)key; |
@end |
Get Cocoa in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.