---
title: toRect()
framework: javascriptcore
role: symbol
role_heading: Instance Method
path: javascriptcore/jsvalue/torect()
---

# toRect()

Converts the value to a rectangle structure.

## Declaration

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

## Return Value

Return Value A CoreGraphics point representation of the value.

## Discussion

Discussion This method treats the value as a JavaScript object, reading the values of its x, y, width, and height properties using the toDouble() method and creating a 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).

## See Also

### Reading and Converting JavaScript Values

- [toObject()](javascriptcore/jsvalue/toobject().md)
- [toObjectOf(_:)](javascriptcore/jsvalue/toobjectof(_:).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)
- [toSize()](javascriptcore/jsvalue/tosize().md)
