home *** CD-ROM | disk | FTP | other *** search
- // EOKeyValueCoding.h
- // Copyright (c) 1994, NeXT Software, Inc. All rights reserved.
- //
- // The EOKeyValueCoding categories define methods to initialize an object with
- // values stored in a dictionary, and to extract values from an object for a
- // set of keys. These keys are usually the internal names of attributes or
- // relationships as defined in an EOModel, and are used in both the access
- // and interface layers.
- //
-
- #import <Foundation/Foundation.h>
- #import <EOControl/EONull.h>
-
- @interface NSObject (EOKeyValueCodingPrimitives)
-
- - (void)flushKeyBindings;
- // Invalidates the cached key binding information for the receiver's
- // class. This method should be invoked whenever a class is modified or
- // removed from the runtime system. This will be called automatically
- // when bundles are loaded.
-
- - (id)valueForKey:(NSString *)key;
- // The default implementation searches first for a selector with
- // the same name as the key, and then for an instance variable with
- // the same name as the key. Classes can override this method to
- // add custom behavior.
- // Default implementation raises an exception if an unknown key is
- // passed in.
-
- - (void)takeValue:(id)value forKey:(NSString *)key;
- // Sets property of the receiver with supplied values.
- // The default implementation searches first for a selector named
- // setKey: (where "Key" is replaced by the key in the dictionary),
- // and then for an instance variable with the same name as the key.
- // Classes can override this method to add custom behavior.
- // Default implementation raises an exception if an unknown key is
- // passed in.
-
- + (BOOL)accessInstanceVariablesDirectly;
- // This method can be overridden on a class to disable
- // accessing instance variables when a matching method
- // cannot be found. Default on NSObject is YES.
- @end
-
- @interface NSObject (EOKVCPAdditions)
- - (id)valueForKeyPath:(NSString *)key;
- // A "key path" is a key of the form "relname.property" (with one or
- // more relationship names). For example, [emp valueForKeyPath:@"department.name"]
- // will ask the receiving employee for its department object (via valueForKey:)
- // and will in turn ask the department for its name. This provides attribute
- // "flattening" by navigating the object graph in memory.
-
- - (void)takeValue:value forKeyPath:(NSString *)key;
- // Sets the property identified by the given key path. @"address.street"
- // sent to an employee object will first get the address object (via
- // valueForKey:@"address") and then perform [address setValue:value forKey:@"street"]
-
- - (NSDictionary *)valuesForKeys:(NSArray *)keys;
- // aggregate version of valueForKey:
- // Nil values returned from valueForKey: are put in return dictionary
- // as EONull
-
- - (void)takeValuesFromDictionary:(NSDictionary *)dictionary;
- // aggregate version of takeValue:forKey:
- // EONull in the input dictionary is passed to object as takeValue:nil
-
- @end
-
- @interface NSObject (EOKeyValueCodingException)
- - (id)handleQueryWithUnboundKey:(NSString *)key;
- // Called by default implementation of valueForKey: when the key
- // does not correspond to a method or instance variable in the
- // receiver. The default implementation raises an exception.
- // Classes can override this method to be more permissive
- // (perhaps by returing nil). The return value is passed back
- // from valueForKey:
-
- - (void)handleTakeValue:(id)value forUnboundKey:(NSString *)key;
- // Called by default implementation of takeValue:forKey: when the key
- // does not correspond to a method or instance variable in the
- // receiver. The default implementation raises an exception.
- // Classes can override this method to be more permissive.
- // (perhaps ignoring the error or logging to the console)
-
-
- - (void)unableToSetNilForKey:(NSString *)key;
- // Classes can implement this method to determine the behavior
- // when nil is assigned to a property in an EO that requires
- // a C scalar type (such as int or float). One possible implementation
- // is to call takeValue:forKey: recursively with a special constant
- // value (like [NSNumber numberWithInt:0]) or with an object that will
- // return the desired values to assign for the methods floatValue, intValue,
- // unsignedIntValue, etc.
- @end
-