Make independent copy of UIBezierPath?

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

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

The originalPath does not get modified.


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.


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