Slide 1

Slide 1 text

CHANGES IN SWIFT 2.2 & 3 COCOATBH IRL, MARCH 2016 JASDEV SINGH

Slide 2

Slide 2 text

SWIFT 2.2 SPRING 2016

Slide 3

Slide 3 text

SWIFT LANGUAGE VERSION BUILD CONFIGURATION #if swift(>=2.2) print("supsup") #else ayy lmao // Not parsed #endif > Only allowed operator is >= > 0.1 is the smallest revision unit.

Slide 4

Slide 4 text

NEW SYNTAX FOR ASSOCIATED TYPES Previously, typealias could be used in two contexts. 1. Type Aliases (alternative name for a type) 2. Associated Types (placeholder for a type in a protocol) Starting in 2.2, the latter will be signaled with the associatedtype keyword (removed in 3.0).

Slide 5

Slide 5 text

associatedtype CONTINUED Moving forward, the following snippet will error out: protocol SomeProtocol { associatedtype Container: SequenceType typealias Element = Container.Generator.Element // X } To get around this, use a protocol extension ⭐ protocol SomeProtocol { associatedtype Container: SequenceType } extension SomeProtocol { typealias Element = Container.Generator.Element }

Slide 6

Slide 6 text

FUNCTION SIGNATURE REFERENCES Overloaded functions can now be referenced with their name and argument labels! struct SomeStruct { func ayy(lmao: String) { } func ayy(lmao: String, sup: String) { } } let func1 = SomeStruct.ayy(_:) let func2 = SomeStruct.ayy(_:sup:)

Slide 7

Slide 7 text

DEBUGGING IDENTIFIER SYNTAX CHANGES __FILE__ -> #file __LINE__ -> #line __COLUMN__ -> #column __FUNCTION__ -> #function __DSO_HANDLE__ -> #dsohandle

Slide 8

Slide 8 text

OBJECTIVE-C SELECTOR GENERATION To avoid the error-prone approach of String literals for selectors, #selector(_) has been introduced: let sel = #selector(UIView.insertSubview(_:atIndex:)) // `sel` is a `Selector` "insertSubview:atIndex:"

Slide 9

Slide 9 text

DEPRECATION OF ++ AND -- "IF WE DIDN'T ALREADY HAVE THESE, WOULD WE ADD THEM TO SWIFT 3?"

Slide 10

Slide 10 text

REMOVAL OF C-STYLE for LOOPS Deprecated in 2.2, removed in 3.0

Slide 11

Slide 11 text

FAILABLE AND THROWING CLASS INITIALIZERS CAN EXIT BEFORE SETTING ALL PROPERTIES Reference types used to require all properties to be set prior to exiting in failable/throwing initializers. This issue has been fixed! !

Slide 12

Slide 12 text

TUPLE COMPARISONS Tuples with Equatable elements are now implicitly Equatable ! (works up to sextuples)

Slide 13

Slide 13 text

@OBJC(...) FOR ENUMERATION CASES Cases within an @objc enumeration can receive special names when being bridged back! @objc enum SomeEnum: Int { @objc(SpecialName) case BridgeCase }

Slide 14

Slide 14 text

PREFER AnyGenerator INITIALIZER OVER anyGenerator anyGenerator will be deprecated in 2.2 and removed in 3.0 (general trend of removing global functions)

Slide 15

Slide 15 text

KEYWORDS AS ARGUMENT LABELS Reserved keywords can now be used as argument labels without backticks (with exception to let, var, and inout)

Slide 16

Slide 16 text

SWIFT 3.0 LATE 2016

Slide 17

Slide 17 text

REMOVAL OF SPECIAL CURRYING SYNTAX // Before func curried(x: Int)(y: String) -> Float { return Float(x) + Float(y)! } // After func curried(x: Int) -> String -> Float { return { (y: String) -> Float in return Float(x) + Float(y)! } }

Slide 18

Slide 18 text

BETTER TRANSLATION OF OBJECTIVE-C APIS INTO SWIFT > SE-0005 > Example Diff

Slide 19

Slide 19 text

REMOVAL OF var PARAMETERS Often confused with inout and only saved a line of code. To get around this use: func ayylmao(n: Int) { var n = n // ... }

Slide 20

Slide 20 text

ABI STABILITY ! "ABI stabilization means that applications [...] compiled with future versions of Swift can interact at a binary level with applications [...] compiled with Swift 3.0."

Slide 21

Slide 21 text

MORE COMPLETE GENERICS > Recursive protocol constraints > Constrained extension protocol conformance > Generic subscripts?

Slide 22

Slide 22 text

API DESIGN GUIDELINES

Slide 23

Slide 23 text

SWIFT TESTING W/ SWIFT PACKAGE MANAGER SE-0019

Slide 24

Slide 24 text

inout TO BECOME A TYPE DECORATOR (x: inout T) -> U

Slide 25

Slide 25 text

FULL LIST OF CHANGES !