BT

Swift 3 is out

| by Sergio De Simone Follow 18 Followers on Sep 19, 2016. Estimated reading time: 1 minute |

Swift 3.0 has been released, writes Apple engineer Ted Kremenek, bringing a wealth of changes to the language and its standard library, additions to the Linux port, and the first official release of the Swift Package Manager.

Swift 3 is Swift’s first major release since the language was open sourced by Apple at the end of 2015 and implements about 90 proposals that were discussed and approved through the Swift evolution process.

A number of changes in Swift 3.0 aim to clean up the API, as per the Swift API Design guidelines, by getting rid of a few decisions that might be seen as a legacy of Objective-C. This had the main effect of making Swift syntax shorter and more consistent:

  • requiring to name the first parameter of functions and methods (unless explicitly omitted using _) makes it possible to write:
    
    aString.write(toFile: "filename", atomically: true, encoding: NSUTF8StringEncoding)
    UIFont.preferredFont(forTextStyle: UIFontTextStyleSubheadline) 
    
    instead of:
    aString.writeToFile("filename", atomically: true, encoding: NSUTF8StringEncoding)
    UIFont.preferredFontForTextStyle(UIFontTextStyleSubheadline) 
    
  • omitting needless words allows developers to write
    UIColor.red()
    instead of
    UIColor.redColor()

The two rules described above will work out an even stronger effect when taken jointly, in that, for example, the following statement:

aString.stringByReplacingOccurrencesOfString("A", withString: "a")

becomes:

aString.replacingOccurrences(of: "A", with: "a")

Another area where Swift 3 has streamlined things is in dealing with C functions belonging to several Cocoa frameworks. As an example of that, all Core Graphics functions starting with CGContext, CGAffineTansform, CGPDFDocument, etc. may now be called as if they were methods of an object:

if let ctx = UIGraphicsGetCurrentContext() {
    ctx.setFillColor(UIColor.red().cgColor)
    ...
}
CGAffineTransform(translationX: 64, y: 0)

Swift 3 also contains changes to its syntax that are are aimed to clean up the language, such as removing the ++ and -- operators, var from function parameters, and C-style for loops with conditions and incrementers, all of which are deemed to bring more disadvantages than advantages.

The list of changes in Swift 3 is definitely too large to cover briefly. You can find all the details in the official announcement.

Rate this Article

Adoption Stage
Style

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Tell us what you think

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Very positive news! Dart tread on the heels and Dart 2.0 will be ready soon. by Andrew Mezoni

Apple are great.
But not only Apple loves their own languages and programmers, Google also loves their own languages and programmers and Dart 2.0 will be available very soon (as was announced by Google at Dart Developer Summit 2015 " Dart Today & Tomorrow").

Swift 3.0 came out, will wait soon Dart 2.0.

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

1 Discuss

Login to InfoQ to interact with what matters most to you.


Recover your password...

Follow

Follow your favorite topics and editors

Quick overview of most important highlights in the industry and on the site.

Like

More signal, less noise

Build your own feed by choosing topics you want to read about and editors you want to hear from.

Notifications

Stay up-to-date

Set up your notifications and don't miss out on content that matters to you

BT