Created
September 5, 2017 00:13
-
-
Save sidmani/b7064986044d2bf3f33104b8b63f8122 to your computer and use it in GitHub Desktop.
UIBezierPath, functional programming style
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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