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

# coerceValue(_:to:)

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

```
func coerceValue(_ value: Any, to toClass: AnyClass) -> Any?
```

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

## Discussion

---

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)