<!--
{
  "availability" : [
    "iOS: 4.0.0 -",
    "iPadOS: 4.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.5.0 -",
    "tvOS: -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "CoreGraphics",
  "identifier" : "/documentation/CoreGraphics/CGPath/init(rect:transform:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "Core Graphics",
      "CoreGraphics"
    ],
    "preciseIdentifier" : "c:@F@CGPathCreateWithRect"
  },
  "title" : "init(rect:transform:)"
}
-->

# init(rect:transform:)

Create an immutable path of a rectangle.

```
init(rect: CGRect, transform: UnsafePointer<CGAffineTransform>?)
```

## Parameters

`rect`

The rectangle to add.

`transform`

A pointer to an affine transformation matrix, or `NULL` if no transformation is needed. If specified, Core Graphics applies the transformation to the rectangle before it is added to the path.

## Return Value

A new, immutable path. You are responsible for releasing this object.

## Discussion

This is a convenience function that creates a path of an rectangle. Using this convenience function is more efficient than creating a mutable path and adding an rectangle to it.

Calling this function is equivalent to using [`CGRectGetMinX(_:)`](/documentation/CoreGraphics/CGRectGetMinX(_:)) and related functions to find the corners of the rectangle, then using the [`CGPathMoveToPoint`](/documentation/CoreGraphics/CGPathMoveToPoint), [`CGPathAddLineToPoint`](/documentation/CoreGraphics/CGPathAddLineToPoint), and [`closeSubpath()`](/documentation/CoreGraphics/CGMutablePath/closeSubpath()) functions to draw the rectangle.

---

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)