Slide 1

Slide 1 text

! Swift 4.1 and Swift 5 @ikesyo ʮiOS 11 Programmingʯץߦه೦ Night 2018-01-10 Wed #iOS11book 1

Slide 2

Slide 2 text

@ikesyo • ͍͚͠ΐʔʗ஑ా ᠳ • ͸ͯͳ@ژ౎ • https://twitter.com/ikesyo • https://github.com/ikesyo 2

Slide 3

Slide 3 text

3

Slide 4

Slide 4 text

Swift 4.1 4

Slide 5

Slide 5 text

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

Slide 6

Slide 6 text

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

Slide 7

Slide 7 text

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

Slide 8

Slide 8 text

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

Slide 9

Slide 9 text

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

Slide 10

Slide 10 text

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

Slide 11

Slide 11 text

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

Slide 12

Slide 12 text

Conditional Conformance is coming • SE-0143 Conditional conformances • Generics Manifesto • Swift.org - Conditional Conformance in the Standard Library 12

Slide 13

Slide 13 text

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

Slide 14

Slide 14 text

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

Slide 15

Slide 15 text

Swift 5.0 15

Slide 16

Slide 16 text

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

Slide 17

Slide 17 text

17

Slide 18

Slide 18 text

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

Slide 19

Slide 19 text

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

Slide 20

Slide 20 text

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

Slide 21

Slide 21 text

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

Slide 22

Slide 22 text

Proposals (as of Jan 10) • SE-0194 Derived Collection of Enum Cases • [Proposal] Random Unification #760 • DynamicMemberLookup proposal #774 22

Slide 23

Slide 23 text

DynamicMemberLookup proposal • Dynamic language interoperability • Dynamic proxy APIs • And other APIs (e.g. for JSON processing) 23

Slide 24

Slide 24 text

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

Slide 25

Slide 25 text

! Happy Swift Coding!! ! 25

Slide 26

Slide 26 text

Thank you❗" Sho Ikeda @ikesyo 26