---
title: "toObjectOf(_:)"
framework: javascriptcore
role: symbol
role_heading: Instance Method
path: "javascriptcore/jsvalue/toobjectof(_:)"
---

# toObjectOf(_:)

Converts the JavaScript value to a native object of the specified class.

## Declaration

```swift
func toObjectOf(_ expectedClass: AnyClass!) -> Any!
```

## Parameters

- `expectedClass`: The Objective-C or Swift class type to convert the value to.

## Return Value

Return Value An Objective-C or Swift object representing the JavaScript value, or nil if the value cannot be converted to the expected class.

## Discussion

Discussion Use this method to enforce a specific type conversion from JavaScript, or to retrieve Objective-C or Swift objects of custom classes that were bridged into JavaScript using the JSExport protocol.

## See Also

### Reading and Converting JavaScript Values

- [toObject()](javascriptcore/jsvalue/toobject().md)
- [toBool()](javascriptcore/jsvalue/tobool().md)
- [toDouble()](javascriptcore/jsvalue/todouble().md)
- [toInt32()](javascriptcore/jsvalue/toint32().md)
- [toUInt32()](javascriptcore/jsvalue/touint32().md)
- [toNumber()](javascriptcore/jsvalue/tonumber().md)
- [toString()](javascriptcore/jsvalue/tostring().md)
- [toDate()](javascriptcore/jsvalue/todate().md)
- [toArray()](javascriptcore/jsvalue/toarray().md)
- [toDictionary()](javascriptcore/jsvalue/todictionary().md)
- [toPoint()](javascriptcore/jsvalue/topoint().md)
- [toRange()](javascriptcore/jsvalue/torange().md)
- [toRect()](javascriptcore/jsvalue/torect().md)
- [toSize()](javascriptcore/jsvalue/tosize().md)
