What’s new in swift 4.2?
Abhay Dave
7 June, 2018
What’s new in swift4.2?
WWDC18
Source Compatibility:One Compiler with Three Modes
Source Compatibility
Swift 3:Accepts Swift 3 code that built with Xcode 8
Swift 4:Accepts Swift 4 code that built with Xcode 9.3
Swift 4.2: Same as with Swift 4 but incorporates new Swift-related SDK. improvements
Faster Swift DebugBuilds
Swift Debug Builds
Build speeds of Xcode 10 compared to Xcode 9
swift debugbuilds
Compilation Mode versus Optimization Level
compilation maode
Stop Using Debug with Whole Module Compilation
Module compilation
UsingWhole ModuleforDebugbuilds was a stopgap to improve buildsWhole Moduleprevents incremental builds
UseIncrementalfor Debug builds!
Runtime Optimizations
// Calling Convention: “Owned” (+1 retain)class X { … }func caller() {// ‘x’ created with +1 reference countlet x = X()}foo(x)func foo(x: X) {let y = x.value// Calling Convention: “Owned” (+1 retain)class X { ... }func caller() {// ‘x’ created with +1 reference countlet x = X()foo(x)}func foo(x: X) {let y = x.value...// release x}
Collection of EnumCases
// SE-0194 Derived Collection of Enum Casesenum Gait { case walk case trot case canter case gallop case jog static var allCases: [Gait] = [.walk, .trot, .canter, .gallop]}for gait in Gait.allCases { //This code will never print “jog”! print(gait)}// SE-0194 Derived Collection of Enum Cases with using CaseIterableenum Gait: CaseIterable { case walk case trot case canter case gallop case jog}for gait in Gait.allCases { print(gait) // It will print all cases}
Conditional Conformance
Inconsistent Behavior in Swift 4.0
Why Aren’t All Arrays Equatable?
Conditional Conformance
Conditional Conformance Allows Composition
Synthesized Equatable and Hashable
// SE-0185 Synthesizing Equatable and Hashable Conformancestruct Restaurant: Equatable { let name: String let hasTableService: Bool let kidFriendly: Bool}// SE-0185 Synthesizing Equatable and Hashable Conformancestruct Restaurant: Hashable { let name: String let hasTableService: Bool let kidFriendly: Bool}// Synthesizing Conditional Equatable and Hashableenum Either<Left, Right> { case left(Left) case right(Right)}extension Either: Equatable where Left: Equatable, Right: Equatable { }extension Either: Hashable where Left: Hashable, Right: Hashable { }// This just works!var mySet = Set<Either<Int, String>>()