---
title: "coerceValue(_:to:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/nsscriptcoercionhandler/coercevalue(_:to:)"
---

# coerceValue(_:to:)

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

## Declaration

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

## Parameters

- `value`: The value to coerce.
- `toClass`: The class with which to represent value.

## Return Value

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

## See Also

### Working with handlers

- [registerCoercer(_:selector:toConvertFrom:to:)](foundation/nsscriptcoercionhandler/registercoercer(_:selector:toconvertfrom:to:).md)
