---
title: "addRect(_:)"
framework: coregraphics
role: symbol
role_heading: Instance Method
path: "coregraphics/cgcontext/addrect(_:)"
---

# addRect(_:)

Adds a rectangular path to the current path.

## Declaration

```swift
func addRect(_ rect: CGRect)
```

## Parameters

- `rect`: A rectangle, specified in user space coordinates.

## Discussion

Discussion This is a convenience function that adds a rectangle to a path, starting by moving to the bottom left corner and then adding lines counter-clockwise to create a rectangle, closing the subpath.

## See Also

### Constructing a Current Graphics Path

- [beginPath()](coregraphics/cgcontext/beginpath().md)
- [move(to:)](coregraphics/cgcontext/move(to:).md)
- [addLine(to:)](coregraphics/cgcontext/addline(to:).md)
- [addLines(between:)](coregraphics/cgcontext/addlines(between:).md)
- [addRects(_:)](coregraphics/cgcontext/addrects(_:).md)
- [addEllipse(in:)](coregraphics/cgcontext/addellipse(in:).md)
- [addArc(center:radius:startAngle:endAngle:clockwise:)](coregraphics/cgcontext/addarc(center:radius:startangle:endangle:clockwise:).md)
- [addArc(tangent1End:tangent2End:radius:)](coregraphics/cgcontext/addarc(tangent1end:tangent2end:radius:).md)
- [addCurve(to:control1:control2:)](coregraphics/cgcontext/addcurve(to:control1:control2:).md)
- [addQuadCurve(to:control:)](coregraphics/cgcontext/addquadcurve(to:control:).md)
- [addPath(_:)](coregraphics/cgcontext/addpath(_:).md)
- [closePath()](coregraphics/cgcontext/closepath().md)
- [path](coregraphics/cgcontext/path.md)
- [replacePathWithStrokedPath()](coregraphics/cgcontext/replacepathwithstrokedpath().md)
