Skip to content

Instantly share code, notes, and snippets.

@sidmani
Created September 5, 2017 00:13
Show Gist options
  • Save sidmani/b7064986044d2bf3f33104b8b63f8122 to your computer and use it in GitHub Desktop.
Save sidmani/b7064986044d2bf3f33104b8b63f8122 to your computer and use it in GitHub Desktop.
UIBezierPath, functional programming style
class Path {
private let path: UIBezierPath
init() { self.path = UIBezierPath() }
func move(to point: CGPoint) -> Path {
path.move(to: point)
return self
}
func addArc(withCenter center: CGPoint, radius: CGFloat, startAngle: CGFloat, endAngle: CGFloat, clockwise: Bool) -> Path {
path.addArc(withCenter: center, radius: radius, startAngle: startAngle, endAngle: endAngle, clockwise: clockwise)
return self
}
func addLine(to point: CGPoint) -> Path {
path.addLine(to: point)
return self
}
func close() -> UIBezierPath {
path.close()
return path
}
}
let path = Path()
.move(to: CGPoint(x: 5, y: 5))
.addLine(to: CGPoint(x: 10, y:5))
.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment