(informal protocol)
Framework | /System/Library/Frameworks/Foundation.framework |
Declared in | NSScriptKeyValueCoding.h |
Companion guides |
Cocoa scripting takes advantage of key-value coding to get and set information in scriptable objects. The methods in this category provide additional capabilities for working with key-value coding, including getting and setting key values by index in multivalue keys and coercing (or converting) a key value. Additional methods allow the implementer of a scriptable container class to provide fast access to elements that are being referenced by name and unique ID.
Because Cocoa scripting invokes setValue:forKey:
and mutableArrayValueForKey:
, changes to model objects made by AppleScript scripts are observable using automatic key-value observing.
Note: In Mac OS X version 10.3 and earlier, Cocoa scripting did not invoke setValue:forKey:
or mutableArrayValueForKey:
, so automatic key-value observing notification was not always done for model object changes caused by scripts. Also, In Mac OS X version 10.4, for backward binary compatibility, Cocoa invokes the now-deprecated method takeValue:forKey:
instead of setValue:forKey:
, if takeValue:forKey:
is overridden.
– insertValue:atIndex:inPropertyWithKey:
– removeValueAtIndex:fromPropertyWithKey:
– replaceValueAtIndex:inPropertyWithKey:withValue:
– valueAtIndex:inPropertyWithKey:
– insertValue:inPropertyWithKey:
– valueWithName:inPropertyWithKey:
– valueWithUniqueID:inPropertyWithKey:
Uses type info from the class description and NSScriptCoercionHandler
to attempt to convert value for key to the proper type, if necessary.
- (id)coerceValue:(id)value forKey:(NSString *)key
The method coerceValueFor<Key>:
is used if it exists.
NSScriptKeyValueCoding.h
Inserts an object at the specified index in the collection specified by the passed key.
- (void)insertValue:(id)value atIndex:(NSUInteger)index inPropertyWithKey:(NSString *)key
The method insertIn<Key>:atIndex:
is invoked if it exists. If no corresponding scripting-KVC-compliant method (insertIn<Key>:atIndex:
) is found, this method invokes mutableArrayValueForKey:
and mutates the result.
NSScriptKeyValueCoding.h
Inserts an object in the collection specified by the passed key.
- (void)insertValue:(id)value inPropertyWithKey:(NSString *)key
The method insertIn<Key>:
is used if it exists. Otherwise, raises an NSUndefinedKeyException
. This is part of Cocoa’s scripting support for inserting newly-created objects into containers without explicitly specifying a location.
NSScriptKeyValueCoding.h
Removes the object at the specified index from the collection specified by the passed key.
- (void)removeValueAtIndex:(NSUInteger)index fromPropertyWithKey:(NSString *)key
The method removeFrom<Key>AtIndex:
is invoked if it exists. If no corresponding scripting-KVC-compliant method (-removeFrom<Key>AtIndex:
) is found, this method invokes -mutableArrayValueForKey:
and mutates the result.
NSScriptKeyValueCoding.h
Replaces the object at the specified index in the collection specified by the passed key.
- (void)replaceValueAtIndex:(NSUInteger)index inPropertyWithKey:(NSString *)key withValue:(id)value
The method replaceIn<Key>:atIndex:
is invoked if it exists. If no corresponding scripting-KVC-compliant method (-replaceIn<Key>atIndex:
) is found, this method invokes -mutableArrayValueForKey:
and mutates the result.
NSScriptKeyValueCoding.h
Retrieves an indexed object from the collection specified by the passed key.
- (id)valueAtIndex:(NSUInteger)index inPropertyWithKey:(NSString *)key
This actually works with a single-value key as well if index is 0. The method valueIn<Key>AtIndex:
is used if it exists.
NSScriptKeyValueCoding.h
Retrieves a named object from the collection specified by the passed key.
- (id)valueWithName:(NSString *)name inPropertyWithKey:(NSString *)key
The method valueIn<Key>WithName:
is used if it exists. Otherwise, raises an NSUndefinedKeyException
.
NSScriptKeyValueCoding.h
Retrieves an object by ID from the collection specified by the passed key.
- (id)valueWithUniqueID:(id)uniqueID inPropertyWithKey:(NSString *)key
The method valueIn<Key>WithUniqueID:
is invoked if it exists. Otherwise, raises an NSUndefinedKeyException
. The declared type of uniqueID in the constructed method must be id
, NSNumber *
, NSString *
, or one of the scalar types that can be encapsulated by NSNumber
.
NSScriptKeyValueCoding.h
NSScriptKeyValueCoding
defines the following exception.
extern NSString *NSOperationNotSupportedForKeyException;
NSOperationNotSupportedForKeyException
Can be raised by key-value coding methods that want to explicitly disallow certain manipulations or accesses.
For instance, a setKey:
method for a read-only key can raise this exception.
Available in Mac OS X v10.0 and later.
Declared in NSScriptKeyValueCoding.h
.
NSScriptKeyValueCoding.h
© 2007 Apple Inc. All Rights Reserved. (Last updated: 2007-10-31)