Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
What's new in Swift 3
1. What’s new in Swift 3
22nd CocoaHeads SP @ Elo7 - Marcio Klepacz
@marciok
2. Agenda
• Introduction
• Where to find Swift 3
• A Swift more “Swifty”
• New Foundation Value Types
• Safety Increased
• Coolness with SPM
• Conclusion
4. 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
6. Where to find Swift 3
• Xcode 8 (Beta)
• swift.org snapshots
7. 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.
9. 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”.
12. 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
15. Example
let dateComponent = NSDateComponents()
dateComponent.year = 2016
let anotherComponent = dateComponent
anotherComponent.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 = dateComponent
anotherComponent.year = 2017 //`dateComponent` is still 2016
Before:
Swift 2
After: Swift 3
19. 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
20. Coolness with SPM
• Examples:
• SwiftyRuby - Calling Ruby from Swift
• SwiftyJava - Calling Java from Swift
22. 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.