What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in...

172
© 2016 Apple Inc. All rights reserved. Redistribution or public display not permitted without written permission from Apple. Developer Tools #WWDC16 Session 402 What’s New in Swift Ted Kremenek Chris Lattner Ewa Matejska

Transcript of What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in...

Page 1: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

© 2016 Apple Inc. All rights reserved. Redistribution or public display not permitted without written permission from Apple.

Developer Tools #WWDC16

Session 402

What’s New in Swift

Ted KremenekChris LattnerEwa Matejska

Page 2: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

Goals for Swift 3

Page 3: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

Goals for Swift 3

Develop an open community

Page 4: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

Goals for Swift 3

Develop an open communityPortability to new platforms

Page 5: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

Goals for Swift 3

Develop an open communityPortability to new platformsGet the fundamentals right

Page 6: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

Goals for Swift 3

Develop an open communityPortability to new platformsGet the fundamentals rightOptimize for awesomeness

Page 7: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift
Page 8: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

Swift Adoption at Apple

Page 9: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

Swift Adoption at Apple

Page 10: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

Agents and DaemonsMusic Console

Page 11: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift
Page 12: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift
Page 13: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

Dock

Page 14: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

Dock

Mission Control LaunchPad

Dashboard

Spaces

Accelerated Two Up

Command-Tab Application Switcher

Dock Bar at Bottom

Some of Notification System

Stacks

Page 15: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

What Changed from El Capitan to Sierra?

Most of Mission Control completely rewritten in SwiftAccessibility engine completely rewritten in Swift

Page 16: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

Lines of codeProject Evolution

Page 17: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

Lines of codeProject Evolution

Dock is ~200,000 lines of code

Page 18: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

Lines of codeProject Evolution

Dock is ~200,000 lines of code2.5x more Swift code

Page 19: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

Lines of codeProject Evolution

Dock is ~200,000 lines of code2.5x more Swift code15% less code to rewrite the same functionality in Swift

Page 20: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

Lines of codeProject Evolution

Dock is ~200,000 lines of code2.5x more Swift code15% less code to rewrite the same functionality in SwiftNew features were added at the same time

Page 21: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

swift.org

Page 22: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift
Page 23: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift
Page 24: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

Swift Open Source

Open evolution processNon-Apple contributors with direct commit accessCode of conductApache 2 with Runtime Library Exception

Page 25: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

Downloadable Toolchains

Download toolchains as Swift develops!• Xcode (Apple platforms) and Linux• Built by continuous integration system

Playground support in Xcode 8 (coming soon)

Page 26: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift
Page 27: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

Swift.org Projects on

Page 28: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

Swift.org Projects on

swift swift-llbuild

swift-clang

swift-llvm

swift-corelibs-foundation

swift-corelibs-xctest

swift-package-manager

swift-lldb

swift-corelibs-libdispatch

swift-evolution

Page 29: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

swift

swift-package-manager

swift-llbuildswift-lldb

swift-clang

swift-llvm

swift-corelibs-foundation

swift-corelibs-libdispatch

swift-corelibs-xctest

swift-evolution

Page 30: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

swift

swift-package-managerswift-llbuild

swift-corelibs-foundationswift-corelibs-libdispatch

swift-corelibs-xctest

swift-evolution

Core LibrariesPackage Manager

Language

Page 31: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

Swift Package Manager

swift-package-managerswift-llbuild

Package Manager

Page 32: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

Swift Package Manager

swift-package-managerswift-llbuild

Package ManagerEarly and actively in development

Page 33: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

Swift Package Manager

Early and actively in developmentCross-platform packages

Page 34: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

Swift Package Manager

Early and actively in developmentCross-platform packagesDesigned for frictionless development

Page 35: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

Swift Package Manager

Early and actively in developmentCross-platform packagesDesigned for frictionless developmentGreat Xcode integration in the future

Page 36: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

swift

swift-package-managerswift-llbuild

swift-corelibs-foundationswift-corelibs-libdispatch

swift-corelibs-xctest

swift-evolution

Package Manager

Language

Core Libraries

Page 37: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

swift

swift-package-managerswift-llbuild

swift-evolution

Package Manager

Language

Core Libraries

Page 38: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

swift

swift-package-managerswift-llbuild

swift-evolution

Package Manager

Language

Core Libraries

swift-corelibs-foundationswift-corelibs-libdispatch

swift-corelibs-xctest

Page 39: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

Foundation on Linux

Page 40: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

Foundation on Linux

AffineTransform

Decimal

PersonNameComponents

URLDate

DateComponents

Measurement

URLQueryItem

IndexSetIndexPath

URLRequest

CharacterSet

Data

DateInterval

Notification URLComponents

UUID

Page 41: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

swiftswift-evolution

swift-package-managerswift-llbuild

swift-corelibs-foundationswift-corelibs-libdispatch

swift-corelibs-xctest

Package Manager

Language

Core Libraries

Page 42: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

swiftswift-evolution

Language

Page 43: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

swiftswift-evolution

Language

Page 44: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

swift-evolution

Page 45: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

Language Evolution Process

Page 46: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

Language Evolution Process

Socialize change on mailing list

Page 47: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

Language Evolution Process

Socialize change on mailing listProposal submitted as a pull request

SE-0046

Page 48: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

Language Evolution Process

Socialize change on mailing listProposal submitted as a pull requestPull request accepted to start review

Page 49: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

Language Evolution Process

Socialize change on mailing listProposal submitted as a pull requestPull request accepted to start reviewFormal review on mailing lists

Page 50: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

Language Evolution Process

Socialize change on mailing listProposal submitted as a pull requestPull request accepted to start reviewFormal review on mailing listsCore team arbitrates a decision

Page 51: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift
Page 52: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

Language and Experience

Chris Lattner

Page 53: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

Making the Core Experience Great

Improve overall experienceof writing Swift code• Swift language• Standard library• Cocoa in Swift• Tools

Page 54: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

Primary goal of Swift 3Zeroing in on Source Compatibility

Source compatibility is the most popular “feature” requestEspecially critical for cross-platformSource compatibility between Swift 3 and 4 is a very strong goal*

Page 55: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

Primary goal of Swift 3Zeroing in on Source Compatibility

Source compatibility is the most popular “feature” requestEspecially critical for cross-platformSource compatibility between Swift 3 and 4 is a very strong goal*

* But not an absolute promise

Page 56: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

API Naming

Page 57: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

Carefully studied what is important in API design• Strive for clarity—not terseness or verbosity• Capture essential information• Omit redundant information/boilerplate

Naming Guidelines

SE-0023 SE-0005 SE-0006

Page 58: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

Carefully studied what is important in API design• Strive for clarity—not terseness or verbosity• Capture essential information• Omit redundant information/boilerplate

Naming Guidelines

SE-0023 SE-0005 SE-0006

https://swift.org/documentation/api-design-guidelines/

Page 59: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

Example API Changes

Swift.Array

array.append array.insert(1, atIndex: 0)

[2,3,4])(ontentsOfC

Page 60: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

Example API Changes

Swift.Array

Foundation.NSURL

array.append array.insert(1, atIndex: 0)

[2,3,4])(ontentsOfC

if url. x = url.

ileURL {}fURLByAppendingPathComponent("file.txt")

Page 61: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

Example API Changes

Swift.Array

Foundation.NSURL

[2,3,4])array.append array.insert(1, atIndex: 0)

( ontentsOfc

if url. x = url.

ileURL {}fURLByAppendingPathComponent("file.txt")

:

Page 62: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

Example API Changes

Swift.Array

Foundation.NSURL

[2,3,4])array.append array.insert(1, at: 0)

( ontentsOfc

if url. x = url.

ileURL {}fURLByAppendingPathComponent("file.txt")

:

Page 63: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

Example API Changes

Swift.Array

Foundation.NSURL

[2,3,4])array.append array.insert(1, at: 0)

( ontentsOfc

if url. x = url.

ileURL {}isFURLByAppendingPathComponent("file.txt")

:

Page 64: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

Example API Changes

Swift.Array

Foundation.NSURL

[2,3,4])array.append array.insert(1, at: 0)

( ontentsOfc

if url. x = url.

ileURL {}isFappendingPathComponent("file.txt")

:

Page 65: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

Example API Changes

Swift.Array

Foundation.NSURL

Swift API Design Guidelines Presidio Tuesday 10:00AM

[2,3,4])array.append array.insert(1, at: 0)

( ontentsOfc

if url. x = url.

ileURL {}isFappendingPathComponent("file.txt")

:

Page 66: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

Importing Objective-C APIs

Page 67: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

Import as Membervoid CGContextFillPath(CGContextRef)

SE-0044

;

Page 68: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

Import as Membervoid CGContextFillPath(CGContextRef)

func CGContextFillPath(_: CGContext)

Swift 2

SE-0044

;

Page 69: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

Import as Membervoid CGContextFillPath(CGContextRef)

func CGContextFillPath(_: CGContext) extension CGContext { func fillPath() }

NS_SWIFT_NAME(CGContext.fillPath(self:));

Swift API Design Guidelines Presidio Tuesday 10:00AM

Swift 2 Swift 3

SE-0044

Page 70: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

Objective-C Generics

SE-0057

func findAnimals() {   let request = NSFetchRequest(entityName:”Animal")   guard let searchResults = try? context.executeFetchRequest(request) as! [Animal] {     return  }   ... use(searchResults) }

Page 71: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

SE-0057

Objective-C Generics

func findAnimals() {   let request : NSFetchRequest<Animal> = Animal.fetchRequest   guard let searchResults = try? context.fetch(request) {

    return  }   ... use(searchResults) }

Page 72: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

Typed Objective-C ConstantsStringly

typedef NSString *NSNotificationName; const NSNotificationName NSUserDefaultsDidChangeNotification;

SE-0033

Page 73: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

D

Typed Objective-C Constants

Imported definitionUserDefaults idChangeNotification: Stringlet NS

Stringly

typedef NSString *NSNotificationName; const NSNotificationName NSUserDefaultsDidChangeNotification;

SE-0033

Page 74: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

idChangeNotificationUserDefaults

D

D

Typed Objective-C Constants

center.addObserver(forName:

Imported definitionUserDefaults idChangeNotification: Stringlet NS

, …)NS

Stringly

typedef NSString *NSNotificationName; const NSNotificationName NSUserDefaultsDidChangeNotification;

Use

SE-0033

Page 75: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

idChangeNotificationUserDefaultsD

Typed Objective-C Constants

center.addObserver(forName:

Imported definitionUserDefaults idChangeNotification: Stringlet NS

, …)NS

Stringly

typedef NSString *NSNotificationName; const NSNotificationName NSUserDefaultsDidChangeNotification;

NS_EXTENSIBLE_STRING_ENUM;

Use

d

SE-0033

Page 76: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

NSNotification.Nameextension { UserDefaults

idChangeNotificationd :let}class

Typed Objective-C ConstantsStringly

typedef NSString *NSNotificationName; const NSNotificationName NSUserDefaultsDidChangeNotification;

NS_EXTENSIBLE_STRING_ENUM;

idChangeNotificationUserDefaultsD center.addObserver(forName: , …)NS

Imported definition

Use

SE-0033

Page 77: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

NSNotification.Nameextension { UserDefaults

idChangeNotificationd :let}class

Typed Objective-C ConstantsStringly

typedef NSString *NSNotificationName; const NSNotificationName NSUserDefaultsDidChangeNotification;

NS_EXTENSIBLE_STRING_ENUM;

idChangeNotificationUserDefaultsdcenter.addObserver(forName: , …)NS

Imported definition

Use

SE-0033

Page 78: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

Typed Objective-C Constants

center.addObserver(forName: , …)UserDefaults idChangeNotificationd.

Stringly

NSNotification.Nameextension { UserDefaults

idChangeNotificationd :let}class

typedef NSString *NSNotificationName; const NSNotificationName NSUserDefaultsDidChangeNotification;

NS_EXTENSIBLE_STRING_ENUM;

Imported definition

Use

SE-0033

Page 79: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

Typed Objective-C Constants

center.addObserver(forName: , …)UserDefaults idChangeNotificationd

Strongly

.

NSNotification.Nameextension { UserDefaults

idChangeNotificationd :let}class

typedef NSString *NSNotificationName; const NSNotificationName NSUserDefaultsDidChangeNotification;

NS_EXTENSIBLE_STRING_ENUM;

Imported definition

Use

SE-0033

Page 80: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

Improvements Throughout the SDK

Major work on Foundation, Dispatch, and Core Graphics

Countless smaller improvements• Ongoing nullability audit • Adoption of Objective-C generics• And more…

Page 81: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

Improvements Throughout the SDK

Major work on Foundation, Dispatch, and Core Graphics

Countless smaller improvements• Ongoing nullability audit • Adoption of Objective-C generics• And more…

What’s New in Foundation for Swift Mission Tuesday 4:00PM

Concurrent Programming with GCD in Swift 3 Pacific Heights Friday 4:00PM

Page 82: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

Core Language

Page 83: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

Consistent Parameter Labeling

func myFunction(a: Int, b: Int, c: Int) { }

SE-0046

Page 84: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

Consistent Parameter Labeling

Swift 2

myFunction(

func myFunction(a: Int, b: Int, c: Int) { }

42, b: 57, c: 99)

SE-0046

Page 85: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

Consistent Parameter Labeling

Swift 3

myFunction(

func myFunction(a: Int, b: Int, c: Int) { }

a: 42, b: 57, c: 99)

SE-0046

Page 86: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

Simpler and more consistentAPI naming often encourages first parameter labelAny parameter label may be suppressed with _

Consistent Parameter Labeling

Swift 3

myFunction(

func myFunction(a: Int, b: Int, c: Int) { }

a: 42, b: 57, c: 99)

SE-0046

Page 87: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

Move ‘where’ Clause to End of Declaration

func anyCommon<T: Sequence, U: Sequence >(lhs: T, rhs: U) -> Bool {

SE-0081

COMING SOON!

Page 88: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

Move ‘where’ Clause to End of Declaration

where T.Element: Equatable, T.Element == U.Element

func anyCommon<T: Sequence, U: Sequence

>(lhs: T, rhs: U) -> Bool {

SE-0081

COMING SOON!

Page 89: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

Move ‘where’ Clause to End of Declaration

where T.Element: Equatable, T.Element == U.Element

Swift 2

func anyCommon<T: Sequence, U: Sequence

>(lhs: T, rhs: U) -> Bool {

SE-0081

COMING SOON!

Page 90: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

Move ‘where’ Clause to End of Declaration

where T.Element: Equatable, T.Element == U.Element

func anyCommon<T: Sequence, U: Sequence>(lhs: T, rhs: U) -> Bool{where T.Element: Equatable, T.Element == U.Element

Swift 3

Swift 2

func anyCommon<T: Sequence, U: Sequence

>(lhs: T, rhs: U) -> Bool {

SE-0081

COMING SOON!

Page 91: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

Warn on Unused Results by Default

func plusOne(_ a: Int) -> Int {

plusOne(x)

return a+1 }

SE-0047

Page 92: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

Warn on Unused Results by Default

func plusOne(_ a: Int) -> Int {

plusOne(x)

return a+1 }

Result of call to ‘plusOne’ is unused

SE-0047

Page 93: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

Warn on Unused Results by Default

func plusOne(_ a: Int) -> Int {

plusOne(x)

return a+1 }

print(a) // side effect!

Result of call to ‘plusOne’ is unused

SE-0047

Page 94: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

Warn on Unused Results by Default

func plusOne(_ a: Int) -> Int {

plusOne(x)_ = plusOne(x)

return a+1 }

print(a) // side effect!

Result of call to ‘plusOne’ is unused

SE-0047

Page 95: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

Warn on Unused Results by Default

func plusOne(_ a: Int) -> Int {

plusOne(x)_ = plusOne(x)

return a+1 }

print(a) // side effect!

@discardableResult

SE-0047

Page 96: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

Features Removed in Swift 3

Page 97: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

Features Removed in Swift 3

Page 98: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

Features Removed in Swift 3Focus and simplify the languageReduce language complexityTeaching and learning

Page 99: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

Features Removed in Swift 3Focus and simplify the languageReduce language complexityTeaching and learning

SE-0002 Currying func declaration syntax

SE-0003 var in function parameter lists

SE-0004 ++ and -- operators

SE-0007 C-style for loop

SE-0029 Implicit tuple splat in calls

What got removed?

Page 100: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

Other small enhancementsCore Language

Page 101: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

Other small enhancementsCore Language

Page 102: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

Other small enhancementsCore Language COMING

SOON!

SE-0025 Scoped access level, new fileprivate access level

SE-0043 case labels with multiple variable bindings

SE-0048 Generic Type Aliases

SE-0062 Referencing Objective-C key-paths

SE-0064 Referencing the selector for property getters and setters

SE-0068 Expanding Self to class members and value types

SE-0075 Adding a build configuration “is importable” test

SE-0092 Typealiases in protocols and protocol extensions

Page 103: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

Core LanguageSyntactic cleanups

Page 104: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

Core LanguageSyntactic cleanups

Page 105: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

Core LanguageSyntactic cleanups

SE-0028 Replace __FILE__ with #file

SE-0031 inout moved to be part of the type

SE-0036 Requiring leading dot prefixes for enum instance members

SE-0040 Attribute syntax: replace = with :

SE-0049 Move @noescape and @autoclosure to be type attributes

SE-0060 Enforcing order of defaulted parameters

SE-0066 Standardize function type argument syntax to require parentheses

SE-0096 Converting dynamicType from a property to an operator

Page 106: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

Type System

Page 107: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

Type System Purpose

Type system and type checker work together• Validate correctness of code• Infer types and overloads implicit in code let a = x + y

Page 108: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

Type System Purpose

Type system and type checker work together• Validate correctness of code• Infer types and overloads implicit in code let a = x + yGoal• Simpler, more consistent, and more predictable type system• Remove “gotchas” and surprising behavior• Improve type checker performance

Page 109: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

UnsafePointer Nullability

let ptr : UnsafeMutablePointer<Int>

Swift

= nil

if ptr != nil {ptr

}.memory = 42

2

SE-0055

Page 110: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

UnsafePointer Nullability

let ptr : UnsafeMutablePointer<Int>

Swift

= nil

if let ptr = ptr {ptr

}.memory = 42

3

?

SE-0055

Page 111: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

UnsafePointer Nullability

Imported C pointers in APIs obey _Nullable and _Null_unspecifiedConsistency: nil is dedicated to Optional and ImplicitlyUnwrappedOptional

let ptr : UnsafeMutablePointer<Int> = nil

ptr .memory = 42

?

Swift 3

SE-0002

Page 112: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

UnsafePointer Nullability

Imported C pointers in APIs obey _Nullable and _Null_unspecifiedConsistency: nil is dedicated to Optional and ImplicitlyUnwrappedOptional

let ptr : UnsafeMutablePointer<Int> = nil

ptr .memory = 42

?

?

Swift 3

SE-0002

Page 113: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

Implicitly Unwrapped Optional (IUO)func f(value : Int!) {

}

Swift 2

SE-0054

Page 114: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

Implicitly Unwrapped Optional (IUO)func f(value : Int!) {

}

Swift 2

let x = value + 1 let y = value

SE-0054

Page 115: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

Implicitly Unwrapped Optional (IUO)func f(value : Int!) {

}

Swift 2

let x = value + 1 let y = value

SE-0054

// x: Int - force unwrapped// y: Int!

Page 116: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

Implicitly Unwrapped Optional (IUO)func f(value : Int!) {

}

let array = [value, 42]

use(array)

// [Int], [Int!], [Int?], [Any]...

Swift 2

let x = value + 1 let y = value

SE-0054

// x: Int - force unwrapped// y: Int!

Page 117: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

Implicitly Unwrapped Optional (IUO)func f(value : Int!) {

}

let array = [value, 42]

use(array) Cannot convert value of type ‘[Int!]’ to argument type !

// [Int], [Int!], [Int?], [Any]...

Swift 2

let x = value + 1 let y = value

SE-0054

// x: Int - force unwrapped// y: Int!

Page 118: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

Implicitly Unwrapped Optional (IUO)

“IUO” becomes a strong optional if that will work• It is only forced if necessary to type check

func f(value : Int!) {

}

let array = [value, 42]

use(array)

Swift 3

let x = value + 1 let y = value

SE-0054

Page 119: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

Implicitly Unwrapped Optional (IUO)

“IUO” becomes a strong optional if that will work• It is only forced if necessary to type check

func f(value : Int!) {

}

let array = [value, 42]

use(array)

Swift 3

let x = value + 1 let y = value

// x: Int - force unwrapped

SE-0054

Page 120: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

Implicitly Unwrapped Optional (IUO)

“IUO” becomes a strong optional if that will work• It is only forced if necessary to type check

func f(value : Int!) {

}

let array = [value, 42]

use(array)

Swift 3

let x = value + 1 let y = value // y: Int?

// x: Int - force unwrapped

SE-0054

Page 121: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

Implicitly Unwrapped Optional (IUO)

“IUO” becomes a strong optional if that will work• It is only forced if necessary to type check

func f(value : Int!) {

}

let array = [value, 42]

use(array)

Swift 3

// [Int?]

let x = value + 1 let y = value // y: Int?

// x: Int - force unwrapped

SE-0054

Page 122: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

Implicitly Unwrapped Optional (IUO)

“IUO” becomes a strong optional if that will work• It is only forced if necessary to type check

func f(value : Int!) {

}

let array = [value, 42]

use(array)

Swift 3

// [Int?]

let x = value + 1 let y = value // y: Int?

// x: Int - force unwrapped

SE-0054

// [Int]let array2 = [value!, 42]

Page 123: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

Standard Library

Page 124: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

Collections move their indicesNew Collection Indexing Model

i = collection.startIndex

next = i.successor()

Swift 2

SE-0065

Page 125: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

Collections move their indicesNew Collection Indexing Model

i = collection.startIndex

next = i.successor()

Swift 2

i = collection.startIndex

next = collection.index(after: i)

Swift 3

SE-0065

Page 126: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

Collections move their indicesNew Collection Indexing Model

i = collection.startIndex

next = i.successor()

Benefits• HalfOpenInterval and IntervalType are merged into Range• 0...UInt8.max now works properly• Better performance

Swift 2

i = collection.startIndex

next = collection.index(after: i)

Swift 3

SE-0065

Page 127: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

Floating Point and Numerics

New FloatingPoint protocol unifies Float, Double, Float80, and CGFloat• Provides core IEEE-754 properties and operations • Permits algorithms to be generic over all floating point types

SE-0067

Page 128: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

Floating Point and Numerics

New FloatingPoint protocol unifies Float, Double, Float80, and CGFloat• Provides core IEEE-754 properties and operations • Permits algorithms to be generic over all floating point types

let v = 2 * Float(M_PI)

Swift 2 Swift 3

let v = 2 * Float.pi

SE-0067

Page 129: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

return x *

Floating Point and Numerics

New FloatingPoint protocol unifies Float, Double, Float80, and CGFloat• Provides core IEEE-754 properties and operations • Permits algorithms to be generic over all floating point types

let v = 2 * Float(M_PI)

Swift 2 Swift 3

let v = 2 * Float.pi

return x * CGFloat(M_PI) / 180 CGFloat.pi / 180

SE-0067

Page 130: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

return x *

Floating Point and Numerics

New FloatingPoint protocol unifies Float, Double, Float80, and CGFloat• Provides core IEEE-754 properties and operations • Permits algorithms to be generic over all floating point types

let v = 2 * Float(M_PI)

Swift 2 Swift 3

let v = 2 * Float.pi

return x * CGFloat(M_PI) / 180 .pi / 180

SE-0067

Page 131: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

Other small enhancementsStandard Library

Page 132: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

Other small enhancementsStandard Library

SE-0008 Add a Lazy flatMap for sequences of optionals

SE-0016 Conversions Unsafe[Mutable]Pointer to Int and UInt

SE-0017 Change Unmanaged to use UnsafePointer

SE-0032 Add first(where:) method to Sequence

SE-0061 Add generic result and error handling to autoreleasepool()

SE-0080 Failable numeric conversion initializers

SE-0093 Adding a public base property to slices

SE-0094 Add sequence(first:next:) and sequence(state:next:) to the stdlib

Page 133: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

Swift 3 Language and Experience

API namingImporting Objective-C APIsCore languageType systemStandard library

Page 134: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

Swift Tools

Ewa Matejska

Page 135: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

Smaller Binaries

Faster Type Checking

String Hashing

Incremental Compilation Stack Promotion

Faster Dictionary

Whole Module Optimization

Faster Startup Time

Page 136: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

Dictionary<String, T>

3x

Page 137: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

Heap to Stack Promotion for Classes

24x

Page 138: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

String Algorithm Optimizations

86x

Page 139: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

Whole Module Optimization

Page 140: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

Whole Module Optimization

File1.swift

File2.swift

File3.swift

Compiler

Compiler

Compiler

File1.o

File2.o

File3.o

Page 141: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

Whole Module Optimization

File1.swift

File2.swift

File3.swift

Compiler

Compiler

Compiler

File1.o

File2.o

File3.o

Page 142: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

Whole Module Optimization

File1.swift

File2.swift

File3.swift

Compiler File2.o

Page 143: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

Whole Module Optimization

File1.swift

File2.swift

File3.swift

Compiler Module.o

Page 144: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

WMO on by Default for New Projects

Page 145: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

What About Compile Time?

File2.swift

File1.swift

File3.swift

Compiler Module.o

Page 146: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

What About Compile Time?

File2.swift

File1.swift

File3.swift

Compiler Module.o

Page 147: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

What About Compile Time?

File2.swift

File1.swift

File3.swift

Compiler Module.o

Page 148: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

Code Size Optimization

DemoBots

AlamoFire

Code Size—Swift 3 vs. Swift 2.20.25 0.5 0.75 1

95%

77%

Page 149: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

Xcode

Page 150: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

Synthesized Interfaces

//: Playground - noun: a place where people can play

let exampleArray = Array<Int>() exampleArray.sort()

Page 151: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

Synthesized Interfaces

/// An ordered, random-access collection. /// ... extension MutableCollectionType where Self.Generator.Element : Comparable {

/// Returns an `Array` containing the sorted elements of `source`. /// ... @warn_unused_result(mutable_variant="sortInPlace") public func sort() -> [Self.Generator.Element] }

/// ...

Page 152: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

Flattening Protocols into APIs

/// An ordered, random-access collection. /// … extension Array where Element : Comparable {

/// Returns the elements of the collection, sorted. /// … public func sorted() -> [Element]

/// … }

Page 153: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

Grouping by Logical Area

/// An ordered, random-access collection. /// … extension Array where Element : Comparable {

/// Returns the elements of the collection, sorted. /// … public func sorted() -> [Element]

/// … }

Page 154: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift
Page 155: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift
Page 156: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

Migrating from Swift 2.2

Page 157: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

Migrating from Swift 2.2

Page 158: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

What Is Swift 2.3?

Swift 2.2

+ =

Swift 2.3New SDKs

Page 159: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

What Is Swift 2.3?

Page 160: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

What Is Swift 2.3?

Build, test, and submit to App Store fully supported

Page 161: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

What Is Swift 2.3?

Build, test, and submit to App Store fully supported

Playgrounds and documentation depend on Swift 3

Page 162: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

What Is Swift 2.3?

Build, test, and submit to App Store fully supported

Interim solution until you migrate to Swift 3

Playgrounds and documentation depend on Swift 3

Page 163: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

Working with Swift 2.2 and Swift 2.3

var groupBackgroundImage: UIImage {

UIGraphicsBeginImageContextWithOptions(groupBackgroundImageSize, false, 2.0)

drawCompleteItemsCountInCurrentContext()

let frame = UIGraphicsGetImageFromCurrentImageContext()

UIGraphicsEndImageContext()

return frame

}

SE-0020

Page 164: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

Working with Swift 2.2 and Swift 2.3

var groupBackgroundImage: UIImage {

UIGraphicsBeginImageContextWithOptions(groupBackgroundImageSize, false, 2.0)

drawCompleteItemsCountInCurrentContext()

let frame = UIGraphicsGetImageFromCurrentImageContext()

UIGraphicsEndImageContext()

return frame

}

!

SE-0020

Page 165: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

Working with Swift 2.2 and Swift 2.3

var groupBackgroundImage: UIImage {

UIGraphicsBeginImageContextWithOptions(groupBackgroundImageSize, false, 2.0)

drawCompleteItemsCountInCurrentContext()

let frame = UIGraphicsGetImageFromCurrentImageContext()

UIGraphicsEndImageContext()

return frame

}

#if swift(>=2.3)

#else

return frame

#endif

!

SE-0020

Page 166: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

From Swift 2.3 to Swift 3

Page 167: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

Summary

Swift 3 focuses on fundamentalsSee swift.org for how to get involvedMigrator available to Swift 3

Page 168: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

More Information

https://developer.apple.com/wwdc16/402

Page 169: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

Related Sessions

Swift API Design Guidelines Presidio Tuesday 10:00AM

Getting Started with Swift Pacific Heights Tuesday 1:40PM

What’s New in Foundation for Swift Mission Tuesday 4:00PM

Introducing Swift Playgrounds Mission Wednesday 11:00AM

Going Server-Side with Swift Open Source Mission Friday 9:00AM

Understanding Swift Performance Mission Friday 11:00AM

Concurrent Programming with GCD in Swift 3 Pacific Heights Friday 4:00PM

Page 170: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

Subtitle

Swift Open Hours Developer Tools Lab A Tuesday 12:00PM

Swift Open Hours Developer Tools Lab A Tuesday 3:00PM

Swift Open Hours Developer Tools Lab A Wednesday 9:00AM

Swift Open Hours Developer Tools Lab A Wednesday 12:00PM

Swift Open Hours Developer Tools Lab A Wednesday 3:00PM

Swift Open Hours Developer Tools Lab A Thursday 9:00AM

Swift Open Hours Developer Tools Lab A Thursday 12:00PM

Swift Open Hours Developer Tools Lab A Thursday 3:00PM

Swift Open Hours Developer Tools Lab A Friday 9:00AM

Swift Open Hours Developer Tools Lab A Friday 12:00PM

Swift Open Hours Developer Tools Lab A Friday 3:00PM

Labs

Page 171: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift

SubtitleSwift Open Hours Developer Tools Lab A Tuesday 12:00PM

Swift Open Hours Developer Tools Lab A Tuesday 3:00PM

Swift Open Hours Developer Tools Lab A Wednesday 9:00AM

Swift Open Hours Developer Tools Lab A Wednesday 12:00PM

Swift Open Hours Developer Tools Lab A Wednesday 3:00PM

Swift Open Hours Developer Tools Lab A Thursday 9:00AM

Swift Open Hours Developer Tools Lab A Thursday 12:00PM

Swift Open Hours Developer Tools Lab A Thursday 3:00PM

Swift Open Hours Developer Tools Lab A Friday 9:00AM

Swift Open Hours Developer Tools Lab A Friday 12:00PM

Swift Open Hours Developer Tools Lab A Friday 3:00PM

Swift Open Hours

Labs

Page 172: What’s New in Swift · 2.5x more Swift code 15% less code to rewrite the same functionality in Swift. Lines of code Project Evolution Dock is ~200,000 lines of code 2.5x more Swift