Make independent copy of UIBezierPath? Make independent copy of UIBezierPath? objective-c objective-c

Make independent copy of UIBezierPath?


Create a new, identical path by using the CGPath.

path2 = [UIBezierPath bezierPathWithCGPath:path1.CGPath];

The CGPath property docs state that:

This property contains a snapshot of the path at any given point in time. Getting this property returns an immutable path object that you can pass to Core Graphics functions.


copy() works fine for me as of Swift 4.

let copiedPath = originalPath.copy() as! UIBezierPathcopiedPath.addLine(...)

The originalPath does not get modified.


In addition to @jrturton answer :-

Alternatively we can use :-

 let  path = UIBezierPath(ovalIn: pathRect) let newPath = path.cgPath.copy(strokingWithWidth: strokeWidth, lineCap: .butt, lineJoin: .miter, miterLimit: 0)

enter image description here

Reference