TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

It's Coming: The Great Swift API Transformation

163 pointsby ceeKover 9 years ago

5 comments

TillEover 9 years ago
I hope they do adopt that suggested change to method calls. Swift is a nice language, but there&#x27;s still some awkwardness due to its required compatibility with Objective C. I think if you don&#x27;t come from that background, then having all named arguments <i>except</i> the first one seems really arbitrary and nonsensical.
评论 #11002451 未加载
评论 #11002426 未加载
fleshweaselover 9 years ago
The title they chose implies that they&#x27;re actually changing the APIs to take full advantage of Swift language features. Perhaps they should have named the article &quot;We&#x27;re renaming some classes and methods.&quot;
评论 #11003591 未加载
bjourneover 9 years ago
If it is one that that <i>should</i> be known about Apple software by now, is that things <i>will</i> change from under your feet. :)
评论 #11003482 未加载
评论 #11005641 未加载
Benjammerover 9 years ago
Could they just go all the way and use a mandatory first argument name to make things even more concise? That would get away from something that annoys a lot of people about Swift, the implicitly unnamed first arguments.<p>Something like this:<p><pre><code> 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) } } </code></pre> The difference is mostly that it looks even more concise when using code completion. You would see:<p><pre><code> path.add(LineTo: CGPoint) </code></pre> Instead of:<p><pre><code> path.addLineTo(point: CGPoint)</code></pre>
评论 #11005270 未加载
protomythover 9 years ago
I do wish the Swift developers had allowed actual Objective-C calls in Swift to make it look the same.<p>Objective-C<p><pre><code> [aPath addLineToPoint:CGPointMake(200.0, 40.0)]; </code></pre> proposed<p><pre><code> aPath.(addLineToPoint:CGPoint(200.0, 40.0)); </code></pre> the more complicated example would be:<p>Objective-C<p><pre><code> [object selector1:item1 selector2:item2]; </code></pre> to<p><pre><code> object.(selector1:item1, selector2:item2); </code></pre> although I&#x27;m still not sure about the love of commas
评论 #11002920 未加载