<!--
{
  "availability" : [
    "macCatalyst: 13.0.0 -",
    "macOS: 10.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/NSScriptCoercionHandler/registerCoercer(_:selector:toConvertFrom:to:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSScriptCoercionHandler(im)registerCoercer:selector:toConvertFromClass:toClass:"
  },
  "title" : "registerCoercer(_:selector:toConvertFrom:to:)"
}
-->

# registerCoercer(_:selector:toConvertFrom:to:)

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

```
func registerCoercer(_ coercer: Any, selector: Selector, toConvertFrom fromClass: AnyClass, to toClass: AnyClass)
```

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

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)