Mac Developer Library

Developer

Foundation Framework Reference NSScriptKeyValueCoding Protocol Reference

Options
Deployment Target:

On This Page
Language:

NSScriptKeyValueCoding

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. More...

Inheritance


Not Applicable

Conforms To


Not Applicable

Import Statement


import Foundation @import Foundation;

Availability


Available in OS X v10.0 and later.
  • Inserts an object at the specified index in the collection specified by the passed key.

    Declaration

    Swift

    func insertValue(_ value: AnyObject, atIndex index: Int, inPropertyWithKey key: String)

    Objective-C

    - (void)insertValue:(id)value atIndex:(NSUInteger)index inPropertyWithKey:(NSString *)key

    Discussion

    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.

    Import Statement

    import Foundation

    Availability

    Available in OS X v10.0 and later.

  • Removes the object at the specified index from the collection specified by the passed key.

    Declaration

    Swift

    func removeValueAtIndex(_ index: Int, fromPropertyWithKey key: String)

    Objective-C

    - (void)removeValueAtIndex:(NSUInteger)index fromPropertyWithKey:(NSString *)key

    Discussion

    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.

    Import Statement

    import Foundation

    Availability

    Available in OS X v10.0 and later.

  • Replaces the object at the specified index in the collection specified by the passed key.

    Declaration

    Swift

    func replaceValueAtIndex(_ index: Int, inPropertyWithKey key: String, withValue value: AnyObject!)

    Objective-C

    - (void)replaceValueAtIndex:(NSUInteger)index inPropertyWithKey:(NSString *)key withValue:(id)value

    Discussion

    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.

    Import Statement

    import Foundation

    Availability

    Available in OS X v10.0 and later.

  • Retrieves an indexed object from the collection specified by the passed key.

    Declaration

    Swift

    func valueAtIndex(_ index: Int, inPropertyWithKey key: String) -> AnyObject?

    Objective-C

    - (id)valueAtIndex:(NSUInteger)index inPropertyWithKey:(NSString *)key

    Discussion

    This actually works with a single-value key as well if index is 0. The method valueIn<Key>AtIndex: is used if it exists.

    Import Statement

    import Foundation

    Availability

    Available in OS X v10.0 and later.

  • Inserts an object in the collection specified by the passed key.

    Declaration

    Swift

    func insertValue(_ value: AnyObject!, inPropertyWithKey key: String!)

    Objective-C

    - (void)insertValue:(id)value inPropertyWithKey:(NSString *)key

    Discussion

    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.

    Import Statement

    import Foundation

    Availability

    Available in OS X v10.2 and later.

  • Retrieves a named object from the collection specified by the passed key.

    Declaration

    Swift

    func valueWithName(_ name: String!, inPropertyWithKey key: String!) -> AnyObject!

    Objective-C

    - (id)valueWithName:(NSString *)name inPropertyWithKey:(NSString *)key

    Discussion

    The method valueIn<Key>WithName: is used if it exists. Otherwise, raises an NSUndefinedKeyException.

    Import Statement

    import Foundation

    Availability

    Available in OS X v10.2 and later.

  • Retrieves an object by ID from the collection specified by the passed key.

    Declaration

    Swift

    func valueWithUniqueID(_ uniqueID: AnyObject!, inPropertyWithKey key: String!) -> AnyObject!

    Objective-C

    - (id)valueWithUniqueID:(id)uniqueID inPropertyWithKey:(NSString *)key

    Discussion

    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.

    Import Statement

    import Foundation

    Availability

    Available in OS X v10.2 and later.

  • Uses type info from the class description and NSScriptCoercionHandler to attempt to convert value for key to the proper type, if necessary.

    Declaration

    Swift

    func coerceValue(_ value: AnyObject!, forKey key: String!) -> AnyObject!

    Objective-C

    - (id)coerceValue:(id)value forKey:(NSString *)key

    Discussion

    The method coerceValueFor<Key>: is used if it exists.

    Import Statement

    import Foundation

    Availability

    Available in OS X v10.0 and later.

  • NSScriptKeyValueCoding defines the following exception.

    Declaration

    Swift

    var NSOperationNotSupportedForKeyException: NSString!

    Objective-C

    extern NSString *NSOperationNotSupportedForKeyException;

    Constants

    • 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 OS X v10.0 and later.

    Import Statement