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

👀 Swift 4.1 and Swift 5

Sho Ikeda
January 10, 2018

👀 Swift 4.1 and Swift 5

「iOS 11 Programming」刊行記念 Nightでの発表資料です #iOS11book

https://peaks.connpass.com/event/74553/

Sho Ikeda

January 10, 2018
Tweet

More Decks by Sho Ikeda

Other Decks in Programming

Transcript

  1. 3

  2. Swift 4.1 • https://swift.org/blog/swift-4-1-release-process/ Swift 4.1 is not binary compatible

    with 4.0. It contains a variety of under-the-hood changes that are part of the effort to stabilize the Swift ABI in Swift 5. • The first half of 2018 • https://github.com/apple/swift/blob/master/ CHANGELOG.md#swift-41 5
  3. Implemented proposals (as of Jan 10) • SE-0075 Adding a

    Build Configuration Import Test #if canImport(UIKit) // UIKit-based code #elseif canImport(Cocoa) // OSX code #elseif // Workaround/text, whatever #endif 6
  4. Implemented proposals (as of Jan 10) • SE-0190 Target environment

    platform condition // Before #if (arch(i386) || arch(x86_64)) && (!os(macOS)) print("Simulator") #endif // After #if targetEnvironment(simulator) print("Simulator") #endif 7
  5. Implemented proposals (as of Jan 10) • SE-0157 Support recursive

    constraints on associated types protocol Sequence { associatedtype Element associatedtype SubSequence: Sequence where SubSequence.Element == Element, SubSequence.SubSequence == SubSequence // ... } protocol Collection: Sequence where Self.SubSequence: Collection { // ... } 8
  6. Implemented proposals (as of Jan 10) • SE-0187 Introduce Sequence.compactMap(_:)

    [1, 2].flatMap { [$0, $0 * 3] } // [1, 3, 2, 6] // Deprecated [1, nil, 2].flatMap { $0 } // [1, 2] // Added [1, nil, 2].compactMap { $0 } // [1, 2] [1, nil, 2].compact() // [1, 2] 9
  7. Implemented proposals (as of Jan 10) • SE-0187 Introduce Sequence.compactMap(_:)

    struct S { var name: String } [foo, bar, baz].map { $0.name } // [String] [foo, bar, baz].flatMap { $0.name } // [String] or [Character] 10
  8. Implemented proposals (as of Jan 10) • SE-0184 Unsafe[Mutable][Raw][Buffer]Pointer: add

    missing methods, adjust existing labels for clarity, and remove deallocation size • SE-0185 Synthesizing Equatable and Hashable conformance • DerivedConformanceEquatableHashable.cpp • SE-0186 Remove ownership keyword support in protocols • SE-0188 Make Standard Library Index Types Hashable • SE-0189 Restrict Cross-module Struct Initializers • SE-0191 Eliminate IndexDistance from Collection 11
  9. Conditional Conformance is coming • SE-0143 Conditional conformances • Generics

    Manifesto • Swift.org - Conditional Conformance in the Standard Library 12
  10. Conditional Conformance is coming // Before extension Array where Element:

    Equatable { public static func ==(lhs: [Element], rhs: [Element]) -> Bool { return lhs.elementsEqual(rhs) } } // [Int]: OK [1, 2] == [1, 2] // [Int?]: NG [1, nil, 2] == [1, nil, 2] 13
  11. Conditional Conformance is coming // After extension Array: Equatable where

    Element: Equatable { static func ==(lhs: [Element], rhs: [Element]) -> Bool { ... } } extension Optional: Equatable where Wrapped: Equatable { static func ==(lhs: Wrapped?, rhs: Wrapped?) -> Bool { ... } } // [Int]: OK [1, 2] == [1, 2] // [Int?]: OK [1, nil, 2] == [1, nil, 2] 14
  12. Swift 5.0 https://github.com/apple/swift-evolution/blob/master/README.md • Expected release date: Late 2018 •

    Primary Focus: ABI Stability • Swift ABI Stability Manifesto • ABI Dashboard • Generics features needed for standard library, API resilience, Memory ownership model (carried over from Swift 4) 16
  13. 17

  14. Swift 5.0 • Other Improvements • String ergonomics • Improvements

    to existing standard library facilities • Foundation improvements • Syntactic additions • Laying groundwork for a new concurrency model 18
  15. String ergonomics • String Manifesto String re-evaluation: String is one

    of the most important fundamental types in the language. The standard library leads have numerous ideas of how to improve the programming model for it, without jeopardizing the goals of providing a unicode-correct-by-default model. Our goal is to be better at string processing than Perl! 19
  16. Laying groundwork for a new concurrency model • Async/Await for

    Swift • https://gist.github.com/lattner/ 429b9070918248274f25b714dcfc7619 • @koher Proposalʹ͸ࡌ͍ͬͯͳ͍Swift 5ͷasync/await͕ૉ੖Β͍͠ͱ ࢥ͏ཧ࿦తഎܠ - Qiita (Swift Tweets 2017 Fall) • Concurrency in Swift: One approach • https://gist.github.com/lattner/31ed37682ef1576b16bca1432ea9f782 20
  17. Proposals (as of Jan 10) These seem to be related

    to ABI stability and API resilience. • SE-0192 Non-Exhaustive Enums • SE-0192 Non-exhaustive enums: add unknown case and rename to '@frozen' #777 • SE-0193 Cross-module inlining and specialization 21
  18. Proposals (as of Jan 10) • SE-0194 Derived Collection of

    Enum Cases • [Proposal] Random Unification #760 • DynamicMemberLookup proposal #774 22
  19. DynamicMemberLookup proposal // Written as a = someValue.someMember someValue.someMember =

    a mutateParameter(&someValue.someMember) // Interpreted as a = someValue[dynamicMember: "someMember"] someValue[dynamicMember: "someMember"] = a mutateParameter(&someValue[dynamicMember: "someMember"]) 24