<!--
{
  "availability" : [
    "iOS: 2.0.0 -",
    "iPadOS: 2.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.5.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "QuartzCore",
  "identifier" : "/documentation/QuartzCore/CALayer/convert(_:to:)-tly5",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Core Animation"
    ],
    "preciseIdentifier" : "c:objc(cs)CALayer(im)convertRect:toLayer:"
  },
  "title" : "convert(_:to:)"
}
-->

# convert(_:to:)

Converts the rectangle from the receiver’s coordinate system to the specified layer’s coordinate system.

```
func convert(_ r: CGRect, to l: CALayer?) -> CGRect
```

## Parameters

`r`

A point specifying a location in the coordinate system of `l`.

`l`

The layer into whose coordinate system `r` is to be converted. The receiver and `l` and must share a common parent layer. This parameter may be `nil`.

## Return Value

The rectangle converted to the coordinate system of `l`.

## Discussion

If you specify `nil` for the `l` parameter, this method returns the original rect with an origin added to the layer’s frame’s origin.

The following example shows code that creates two layers, `redLayer` and `yellowLayer`. `yellowLayer` is scaled so that it is half of its original size.

```swift
let layerFrame = CGRect(x: 0, y: 0, width: 640, height: 480)
     
let redLayer = CALayer()
redLayer.frame = layerFrame
redLayer.backgroundColor = UIColor.red.cgColor
     
let yellowLayer = CALayer()
yellowLayer.frame = layerFrame
yellowLayer.backgroundColor = UIColor.yellow.cgColor
yellowLayer.transform = CATransform3DMakeScale(0.5, 0.5, 1)
```

The following figure shows the two layers and an overlaid rectangle with a frame of `(50, 50, 200, 200)` in the red layer’s coordinate system.

![Layers with different coordinate systems](images/com.apple.quartzcore/media-2850323@2x.png)

The following code shows how you can find the coordinates of that rectangle in the yellow layer’s coordinate system.

```swift
let rect = CGRect(x: 50, y: 50, width: 200, height: 200)
print(redLayer.convert(rect, to: yellowLayer)) // prints (-220.0, -140.0, 400.0, 400.0)
```

---

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)