Whereas the post's example compares:
path.addLineToPoint(CGPoint(x: 100, y: 0))
-- to --
path.addLineTo(CGPoint(x: 100, y: 0))
I've been doing it as so: path.addLine(toPoint: CGPoint(x: 100, y: 0))
...requiring the "toPoint", which can swapped out true method overloading style: path.addLine(toArc:...)
In your internal method implementation, Swift allows you to replace the external method name with an internal one, so that it's still nice to work with: func addLine(toPoint point: CGPoint) {
...
}
I personally think it's a lot more readable. Otherwise the first argument has to have a really descriptive class name (recommended for sure, but often not the case). path.addLine(toPoint: CGPoint(x: 100, y: 0))
See the "toPoint: CGPoint". It's useless repetition. The new form eliminates it: path.addLineTo(CGPoint(x: 100, y: 0))
It's clear you're adding a line to a point, because it says "Point" right there. Even if you have a variable for this point already, it works great: path.addLineTo(point)
Or maybe this is a more specifically named point? path.addLineTo(centerPoint)
It's clear from all that you're adding a line to a point. Swift has an emphasis on concise syntax, and removing the repetition, IMO, is a nice win in readability.So the class UIBezierPath and it's method addLineToPoint: haven't changed, and are still written in Obj-C. The difference is in how they're called from Swift code.
Presumably it'll operate the same way in reverse, and this isn't specific to Apple frameworks/classes.
Something like this:
class BezierPath: NSObject {
func add(LineTo lineTo: CGPoint) {}
func add(ArcWithCenter center: CGPoint, radius: CGFloat,
startAngle: CGFloat, endAngle: CGFloat,
clockwise: Bool) {}
func add(CurveTo endPoint: CGPoint, controlPoint1 point1: CGPoint,
controlPoint2 point2: CGPoint) {}
func add(QuadCurveTo endPoint: CGPoint, controlPoint: CGPoint) {}
}
class main {
func run() {
let path = BezierPath()
let point1 = CGPoint()
let point2 = CGPoint()
path.add(LineTo: CGPoint(x: 100, y: 0))
path.add(ArcWithCenter: CGPointZero, radius: 20.0,
startAngle: 0.0, endAngle: CGFloat(M_PI) * 2.0,
clockwise: true)
path.add(CurveTo: CGPoint(x: 100, y: 0), controlPoint1: point1,
controlPoint2: point2)
path.add(QuadCurveTo: point2, controlPoint: point1)
}
}
The difference is mostly that it looks even more concise when using code completion. You would see: path.add(LineTo: CGPoint)
Instead of: path.addLineTo(point: CGPoint)Objective-C
[aPath addLineToPoint:CGPointMake(200.0, 40.0)];
proposed aPath.(addLineToPoint:CGPoint(200.0, 40.0));
the more complicated example would be:Objective-C
[object selector1:item1 selector2:item2];
to object.(selector1:item1, selector2:item2);
although I'm still not sure about the love of commas aPath.addLineToPoint(CGPoint(200.0, 40.0))
I don't see how your proposal would fit with Swift's syntax.