CGContextBeginPath
CGContextBeginPath is a function in Apple’s Core Graphics framework that starts a new drawing path in a graphics context. It is typically called before building a geometric shape, such as lines, curves, or shapes, to clear any existing path data from the context. After the function returns, the current path is empty and ready to receive new drawing commands like CGContextMoveToPoint, CGContextAddLineToPoint, CGContextAddCurveToPoint, and others. The function does not take any parameters besides the current CGContextRef. It simply resets the current path state within the context, but leaves the context’s current graphics state—including line width, stroke color, fill color, and transformations—unchanged. Because it only clears the path, developers can reuse the same graphics context for multiple drawing operations without side effects from previous paths. Calling CGContextBeginPath before each new shape is a common practice, ensuring that strokes and fills are applied only to the intended geometry. The function is thread‑safe as long as the graphics context itself is not shared across threads. It is available in all recent versions of macOS, iOS, tvOS, and watchOS, and forms the foundation for most 2‑D vector drawing routines in Core Graphics.