Contents

copyScriptingValue(_:forKey:withProperties:)

Creates and returns one or more scripting objects to be inserted into the specified relationship by copying the passed-in value and setting the properties in the copied object or objects.

Declaration

func copyScriptingValue(_ value: Any, forKey key: String, withProperties properties: [String : Any]) -> Any?

Parameters

  • value:

    An object or objects to be copied. The type must match the type of the property identified by key. (See also the Discussion section.)

    For example, if the property is a to-many relationship, value will always be an array of objects to be copied, and this method must therefore return an array of objects.

  • key:

    A key that identifies the relationship into which to insert the copied object or objects.

  • properties:

    The properties to be set in the copied object or objects. Derived from the “with properties” parameter of a duplicate command. (See also the Discussion section.)

Return Value

The copied object or objects. Returns nil if an error occurs.

Discussion

You can override the copyScriptingValue method to take more control when your application is sent a duplicate command. This method is invoked on the prospective container of the copied object or objects. The properties are derived from the with properties parameter of the duplicate command. The returned objects or objects are then inserted into the container using key-value coding.

When this method is invoked by Cocoa, neither the value nor the properties will have yet been coerced using the NSScriptKeyValueCoding method coerceValue(_:forKey:). For sdef-declared scriptability, however, the types of the passed-in objects reliably match the relevant sdef declarations.

The default implementation of this method copies scripting objects by sending copyWithZone: to the object or objects specified by value. You override this method for situations where this is not sufficient, such as in Core Data applications, in which new objects must be initialized with [NSManagedObject initWithEntity:insertIntoManagedObjectContext:].

See Also

Scripting