Mac Developer Library

Developer

Foundation Framework Reference NSScriptCoercionHandler Class Reference

Options
Deployment Target:

On This Page
Language:

NSScriptCoercionHandler

Inheritance


  • NSObject
  • NSScriptCoercionHandler
  • NSCoercionHandler
  • NSObject
  • NSScriptCoercionHandler
  • NSCoercionHandler

Conforms To


Import Statement


Swift

import Foundation

Objective-C

@import Foundation;

Availability


Available in OS X v10.0 and later.

Provides a mechanism for converting one kind of scripting data to another. A shared instance of this class coerces (converts) object values to objects of another class, using information supplied by classes that register with it. Coercions frequently are required during key-value coding.

  • Returns the shared NSScriptCoercionHandler for the application.

    Declaration

    Swift

    class func sharedCoercionHandler() -> NSScriptCoercionHandler

    Objective-C

    + (NSScriptCoercionHandler *)sharedCoercionHandler

    Return Value

    The shared NSScriptCoercionHandler for the application.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.0 and later.

  • Returns an object of a given class representing a given value.

    Declaration

    Swift

    func coerceValue(_ value: AnyObject, toClass toClass: AnyClass) -> AnyObject?

    Objective-C

    - (id)coerceValue:(id)value toClass:(Class)toClass

    Parameters

    value

    The value to coerce.

    toClass

    The class with which to represent value.

    Return Value

    An object of the class toClass representing the value specified by value. Returns nil if an error occurs.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.0 and later.

  • Registers a given object (typically a class) to handle coercions (conversions) from one given class to another.

    Declaration

    Swift

    func registerCoercer(_ coercer: AnyObject, selector selector: Selector, toConvertFromClass fromClass: AnyClass, toClass toClass: AnyClass)

    Objective-C

    - (void)registerCoercer:(id)coercer selector:(SEL)selector toConvertFromClass:(Class)fromClass toClass:(Class)toClass

    Parameters

    coercer

    The object that performs the coercion. coercer should typically be a class object.

    selector

    A selector that specifies the method to perform the coercion. selector should typically be a factory method, and must take two arguments. The first is the value to be converted. The second is the class to convert it to.

    fromClass

    The class for which instances are coerced.

    toClass

    The class to which instances of fromClass are coerced.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.0 and later.