<!--
{
  "availability" : [
    "iOS: 7.0.0 -",
    "iPadOS: 7.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.9.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "JavaScriptCore",
  "identifier" : "/documentation/JavaScriptCore/JSValue/toObjectOf(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "JavaScriptCore"
    ],
    "preciseIdentifier" : "c:objc(cs)JSValue(im)toObjectOfClass:"
  },
  "title" : "toObjectOf(_:)"
}
-->

# toObjectOf(_:)

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

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

## Parameters

`expectedClass`

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

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

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`](/documentation/JavaScriptCore/JSExport) protocol.

---

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)