<!--
{
  "availability" : [
    "iOS: 2.0.0 -",
    "iPadOS: 2.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.2.0 -",
    "tvOS: -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "CoreGraphics",
  "identifier" : "/documentation/CoreGraphics/CGPathAddRect",
  "metadataVersion" : "0.1.0",
  "role" : "Function",
  "symbol" : {
    "kind" : "Function",
    "modules" : [
      "Core Graphics"
    ],
    "preciseIdentifier" : "c:@F@CGPathAddRect"
  },
  "title" : "CGPathAddRect"
}
-->

# CGPathAddRect

Appends a rectangle to a mutable graphics path.

```
extern void CGPathAddRect(CGMutablePathRef path, const CGAffineTransform *m, CGRect rect);
```

## Parameters

`path`

The mutable path to change.

`m`

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 adding it to the path.

`rect`

The rectangle to add.

## Discussion

This is a convenience function that adds a rectangle to a path. 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 add each line segment of 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)