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

# toRect()

Converts the value to a rectangle structure.

```
func toRect() -> CGRect
```

## Return Value

A CoreGraphics point representation of the value.

## Discussion

This method treats the value as a JavaScript object, reading the values of its `x`, `y`, `width`, and `height` properties using the [`toDouble()`](/documentation/JavaScriptCore/JSValue/toDouble()) method and creating a <doc://com.apple.documentation/documentation/CoreFoundation/CGRect> structure from the result. If the value is not a JavaScript object or does not have the appropriate properties, each of the resulting rectangle’s coordinates is not a number (NaN).

---

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)