I have the same problem with Xcode Version 16.2 (16C5032a) and none of the proposed solutions works. I solved it by simply adding a line to the path going from top to bottom: just after the segments.forEach loop:
path.move(
to: CGPoint(
x: width * 0.5 + xOffset,
y: 0 )
)
path.addLine(
to: CGPoint(
x: width * 0.5 + xOffset,
y: height
)
)