Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Swift 2.2 & 3.0 Changes

Swift 2.2 & 3.0 Changes

What to expect from upcoming Swift versions. Presented at Tumblr's CocoaTBH IRL

Jasdev Singh

March 09, 2016
Tweet

More Decks by Jasdev Singh

Other Decks in Programming

Transcript

  1. 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.
  2. 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).
  3. 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 }
  4. 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:)
  5. DEBUGGING IDENTIFIER SYNTAX CHANGES __FILE__ -> #file __LINE__ -> #line

    __COLUMN__ -> #column __FUNCTION__ -> #function __DSO_HANDLE__ -> #dsohandle
  6. 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:"
  7. DEPRECATION OF ++ AND -- "IF WE DIDN'T ALREADY HAVE

    THESE, WOULD WE ADD THEM TO SWIFT 3?"
  8. 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! !
  9. @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 }
  10. PREFER AnyGenerator INITIALIZER OVER anyGenerator anyGenerator will be deprecated in

    2.2 and removed in 3.0 (general trend of removing global functions)
  11. KEYWORDS AS ARGUMENT LABELS Reserved keywords can now be used

    as argument labels without backticks (with exception to let, var, and inout)
  12. 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)! } }
  13. 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 // ... }
  14. 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."