what's new in swift 3
TRANSCRIPT
![Page 1: What's new in Swift 3](https://reader036.vdocuments.mx/reader036/viewer/2022081605/5871239a1a28abe4448b59ff/html5/thumbnails/1.jpg)
What’s new in Swift 3 22nd CocoaHeads SP @ Elo7 - Marcio Klepacz
@marciok
![Page 2: What's new in Swift 3](https://reader036.vdocuments.mx/reader036/viewer/2022081605/5871239a1a28abe4448b59ff/html5/thumbnails/2.jpg)
Agenda• Introduction
• Where to find Swift 3
• A Swift more “Swifty”
• New Foundation Value Types
• Safety Increased
• Coolness with SPM
• Conclusion
![Page 3: What's new in Swift 3](https://reader036.vdocuments.mx/reader036/viewer/2022081605/5871239a1a28abe4448b59ff/html5/thumbnails/3.jpg)
Introductionor what to expect from Swift 3
![Page 4: What's new in Swift 3](https://reader036.vdocuments.mx/reader036/viewer/2022081605/5871239a1a28abe4448b59ff/html5/thumbnails/4.jpg)
Swift 3
• Was also brought by proposals from the community.
• Is focused on clarity, at the point of use.
• Brings more clarity when working with legacy APIs
• Safer
![Page 5: What's new in Swift 3](https://reader036.vdocuments.mx/reader036/viewer/2022081605/5871239a1a28abe4448b59ff/html5/thumbnails/5.jpg)
Where to find Swift 3
![Page 7: What's new in Swift 3](https://reader036.vdocuments.mx/reader036/viewer/2022081605/5871239a1a28abe4448b59ff/html5/thumbnails/7.jpg)
Considerations
• You can only submit apps using Swift 3 when Xcode GM is shipped ~end of 2016.
• Swift 3 changes everything. Xcode 8 comes with a code migration tool (can migrate to 2.3). However, I would still check the migrations made by Xcode.
![Page 8: What's new in Swift 3](https://reader036.vdocuments.mx/reader036/viewer/2022081605/5871239a1a28abe4448b59ff/html5/thumbnails/8.jpg)
A Swift more “Swifty”
![Page 9: What's new in Swift 3](https://reader036.vdocuments.mx/reader036/viewer/2022081605/5871239a1a28abe4448b59ff/html5/thumbnails/9.jpg)
Swift more “Swifty”
• Not terse or Verbose code.
• Clarity is more important than brevity.
• Concise code is a consequence of using contextual cues.
• What they mean (In my option) is: Let’s ditch legacy ObjC API designs, and be more “Swifty”.
![Page 10: What's new in Swift 3](https://reader036.vdocuments.mx/reader036/viewer/2022081605/5871239a1a28abe4448b59ff/html5/thumbnails/10.jpg)
Before:
After:
NSTimer.scheduledTimerWithTimeInterval(0.35, target: self, …)
NSTimer.scheduledTimer(timeInterval: 0.35, target: self, …)
UIFont.preferredFontForTextStyle(UIFontTextStyleSubheadline)
UIFont.preferredFont(forTextStyle: UIFontTextStyleSubheadline)
func viewForZoomingInScrollView(scrollView: UIScrollView) -> UIView?
func viewForZooming(in scrollView: UIScrollView) -> UIView?
Swift 2
Swift 3
![Page 11: What's new in Swift 3](https://reader036.vdocuments.mx/reader036/viewer/2022081605/5871239a1a28abe4448b59ff/html5/thumbnails/11.jpg)
Before:
After:func findCocoaheads(in city: String) { //...}
findCocoaheads(in:"São Paulo")
func findCocoaheadsIn(city: String) { //...}
findCocoaheadsIn("São Paulo")
Swift 2
Swift 3
![Page 12: What's new in Swift 3](https://reader036.vdocuments.mx/reader036/viewer/2022081605/5871239a1a28abe4448b59ff/html5/thumbnails/12.jpg)
Before:
After:
UIColor.blueColor()
UIColor.blue() // or simply .blue() if the compile can infer
cocoaheads(insert: “São Paulo” atIndex: 0)
cocoaheads(insert: “São Paulo” at: 0)
NSUserDefaults.standardUserDefaults()
UserDefaults.standard() // NSUserDefaults was renamed to UserDefaults
Swift 2
Swift 3
Omitting needless words
![Page 13: What's new in Swift 3](https://reader036.vdocuments.mx/reader036/viewer/2022081605/5871239a1a28abe4448b59ff/html5/thumbnails/13.jpg)
New Foundation Value Types
![Page 14: What's new in Swift 3](https://reader036.vdocuments.mx/reader036/viewer/2022081605/5871239a1a28abe4448b59ff/html5/thumbnails/14.jpg)
New Foundation value types
![Page 15: What's new in Swift 3](https://reader036.vdocuments.mx/reader036/viewer/2022081605/5871239a1a28abe4448b59ff/html5/thumbnails/15.jpg)
Example
let dateComponent = NSDateComponents()dateComponent.year = 2016let anotherComponent = dateComponentanotherComponent.year = 2017 //`dateComponent` year was also changed to 2017
var dateComponent = DateComponents()dateComponent.year = 2016 // It will warn you if `dateComponent` is a `let`let anotherComponent = dateComponentanotherComponent.year = 2017 //`dateComponent` is still 2016
Before: Swift 2
After: Swift 3
![Page 16: What's new in Swift 3](https://reader036.vdocuments.mx/reader036/viewer/2022081605/5871239a1a28abe4448b59ff/html5/thumbnails/16.jpg)
Safety Increased
![Page 17: What's new in Swift 3](https://reader036.vdocuments.mx/reader036/viewer/2022081605/5871239a1a28abe4448b59ff/html5/thumbnails/17.jpg)
Safety IncreasedBefore:
After:
var cocoaheads = [String!]()cocoaheads.append("São Paulo")let sp = cocoaheads[0]sp.dynamicType // ImplicitlyUnwrappedOptional<String>
Swift 2
Swift 3
var cocoaheads = [String!]()cocoaheads.append("São Paulo")let sp = cocoaheads[0]sp.dynamicType // Optional<String>let dangerousSp: String! = cocoaheads[0]dangerousSp.dynamicType // ImplicitlyUnwrappedOptional<String>
No more `ImplicitlyUnwrappedOptional` propagation
![Page 18: What's new in Swift 3](https://reader036.vdocuments.mx/reader036/viewer/2022081605/5871239a1a28abe4448b59ff/html5/thumbnails/18.jpg)
Coolness with SPM
![Page 19: What's new in Swift 3](https://reader036.vdocuments.mx/reader036/viewer/2022081605/5871239a1a28abe4448b59ff/html5/thumbnails/19.jpg)
Coolness with SPM
• The ability to pass custom flags during linker invocations. Also on C and Swift compilation.
• Export as dynamic library
==
• Easy to Interoperate with other languages
![Page 20: What's new in Swift 3](https://reader036.vdocuments.mx/reader036/viewer/2022081605/5871239a1a28abe4448b59ff/html5/thumbnails/20.jpg)
Coolness with SPM
• Examples:
• SwiftyRuby - Calling Ruby from Swift
• SwiftyJava - Calling Java from Swift
![Page 21: What's new in Swift 3](https://reader036.vdocuments.mx/reader036/viewer/2022081605/5871239a1a28abe4448b59ff/html5/thumbnails/21.jpg)
Conclusion
![Page 22: What's new in Swift 3](https://reader036.vdocuments.mx/reader036/viewer/2022081605/5871239a1a28abe4448b59ff/html5/thumbnails/22.jpg)
Conclusion• Swift 3 changes everything (again). It will force
us get rid of our ObjC muscle muscle memory.
• Was also brought by the community. We can always go on Github to complain, suggest and change.
• There are many others news things that weren’t mentioned at this presentation, so don’t forget to check online for other things.
![Page 23: What's new in Swift 3](https://reader036.vdocuments.mx/reader036/viewer/2022081605/5871239a1a28abe4448b59ff/html5/thumbnails/23.jpg)
Thanks!• Twitter: @marciok
• Github: /marciok
• References:
• https://www.raywenderlich.com/135655/whats-new-swift-3
• https://www.bignerdranch.com/blog/wwdc-2016-increased-safety-in-swift-3/
• https://developer.apple.com/videos/play/wwdc2016/402/