---
title: CGPathAddRect
framework: coregraphics
role: symbol
role_heading: Function
path: coregraphics/cgpathaddrect
---

# CGPathAddRect

Appends a rectangle to a mutable graphics path.

## Declaration

```occ
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

Discussion This is a convenience function that adds a rectangle to a path. Calling this function is equivalent to using CGRectGetMinX(_:) and related functions to find the corners of the rectangle, then using the CGPathMoveToPoint, CGPathAddLineToPoint, and closeSubpath() functions to add each line segment of the rectangle.

## See Also

### Constructing a Graphics Path

- [CGPathMoveToPoint](coregraphics/cgpathmovetopoint.md)
- [CGPathAddLineToPoint](coregraphics/cgpathaddlinetopoint.md)
- [CGPathAddLines](coregraphics/cgpathaddlines.md)
- [CGPathAddRects](coregraphics/cgpathaddrects.md)
- [CGPathAddEllipseInRect](coregraphics/cgpathaddellipseinrect.md)
- [CGPathAddRoundedRect](coregraphics/cgpathaddroundedrect.md)
- [CGPathAddArc](coregraphics/cgpathaddarc.md)
- [CGPathAddArcToPoint](coregraphics/cgpathaddarctopoint.md)
- [CGPathAddRelativeArc](coregraphics/cgpathaddrelativearc.md)
- [CGPathAddCurveToPoint](coregraphics/cgpathaddcurvetopoint.md)
- [CGPathAddQuadCurveToPoint](coregraphics/cgpathaddquadcurvetopoint.md)
- [CGPathAddPath](coregraphics/cgpathaddpath.md)
- [closeSubpath()](coregraphics/cgmutablepath/closesubpath().md)
