Objective-Everything Release 5.
Copyright ©1994-1998 by TipTop Software, Inc. All Rights
Reserved.
Key-Value Extensions
XVars
In the OpenStep object model, instance variables are statically defined when a class is defined. All instances of that class then have exactly the same set of instance variables (of course, the values are different).
One extension to the OpenStep object model that Objective-Everything facilitates is the ability to associate arbitrary object values with any object. In addition to instance variables (IVars), objects can have any number of XVars (eXtra VARiables). I.e., instances of the same class can have different variables.
-
Python
| read:
| value=object.__xv__.xvarname
|
| write:
| object.__xv__.xvarname=value
|
---|
| check:
| object.hasXVar('xvarname')
|
---|
|
Tcl
| read:
| set value [xvarset $object xvarname]
|
| write:
| xvarset $object xvarname $value
|
---|
| check:
| $object hasXVar: [@ xvarname]
|
---|
|
Perl
| read:
| xget $object, 'xvarname'
|
| write:
| xset $object, 'xvarname', $value
|
---|
| check:
| $object->hasXVar_('xvarname')
|
---|
|
ObjC
| read:
| [object valueForXVar:@"xvarname"]
|
| write:
| [object takeValue:value forXVar:@"xvarname"]
|
---|
| check:
| [object hasXVar:@"xvarname"]
|
---|
See the language references for more info on XVars.
Alternate Key-Value Coding
Objective-Everything provides an alternate key-value coding protocol to the standard key-value coding. The standard key value coding protocol specifies two primitive methods:
-
- - (id)valueForKey:(NSString *)key;
- Retrieves the property key value of the receiver.
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.
- - (void)takeValue:(id)value forKey:(NSString *)key;
- Sets the property key of the receiver to the supplied value.
The default implementation searches first for a selector named setKey:,
and then for an instance variable with the same name as the key.
Objective-Everything runtime system provides the alternate key-value coding protocol which, in addition to the above-described standard behavior, allows you to access XVars. Note that the alternate key-value coding methods do not override the default methods. Hence, you have to explicitly invoke them.
-
- - (id)ttValueForKey:(NSString *)key;
- Retrieves the property key value of the receiver.
The default implementation searches first for a selector with the same name as the key, then for an instance variable with the same name as the key, and then for XVar with the same name as the key. If the search fails, an NSInvalidArgumentException exception is raised.
- - (void)ttTakeValue:(id)value forKey:(NSString *)key;
- Sets the property key of the receiver to the supplied value.
The default implementation searches first for a selector named setKey:,
then for an instance variable with the same name as the key, and then for XVar with the same name as the key. If the search fails, XVar key is defined for the receiver object.
In addition to the primive key-value coding methods, the following methods are also provided:
-
- - (BOOL)ttHasKey:(NSString*)key;
- Returns YES if the key exists. I.e., if this methods returns YES, then invocation of -ttValueForKey: will not raise because the key does not exist.
- - (NSEnumerator*)ttKeyEnumerator;
- Returns an enumerator object which can be used to enumerate property keys. The default implementation returns an enumerator for all instance variable keys and all XVar keys.
- - (id)ttValueForKeyPath:(NSString*)path;
- The path is of the form "key1.key2.key3...". This will first invoke -ttValueForKey:key1 on the receiver object, then -ttValueForKey:key2 on the result of that, etc.
- - (void)ttTakeValue:value forKeyPath:(NSString*)path;
- Sets the property identified by the given key path.
- - (NSDictionary *)ttValuesForKeys:(NSArray*)keys;
- Aggregate version of -ttValueForKey:.
- - (void)ttTakeValuesFromDictionary:(NSDictionary*)dictionary;
- Aggregate version of -ttTakeValue:forKey:.
[previous][contents][next]