Slide 1

Slide 1 text

What Will be changed in Swiftɹ v4.0.0(3) Daiki Matsudate / @d_date SwiftѪ޷ձ vol.19

Slide 2

Slide 2 text

ࣗݾ঺հ / Self Introduction ɾFreelance Engineer (2017/05ʙ) ɾ@d_date (Ͱ͌ʔͩͯ/Ͱ͌ʔͰ͍ͱ) ɾiOSྺ6೥ (iOS 4ʙ) ɾDaiki Matsudate ɾWWDCࢀՃ͠·͢✈

Slide 3

Slide 3 text

Qiitaʹهࣄ্͛·ͨ͠

Slide 4

Slide 4 text

Qiitaʹهࣄ্͛·ͨ͠

Slide 5

Slide 5 text

Release Note • v4.0.0(0) 4/15(౔) Swift Tweets #2 • v4.0.0(1) 4/22(౔) Cocoaؔ੢ • v4.0.0(2) 4/28(ۚ) SwiftѪ޷ձ vol.18 • v4.0.0(3) 5/23(Ր) SwiftѪ޷ձ vol.19 • Swift 4 ෮शձ 5/27(౔) Swift Day @ ԭೄ • v4.0.0(4) 6/18(೔) SwiftѪ޷ձ vol.20

Slide 6

Slide 6 text

v4.0.0(3) Update

Slide 7

Slide 7 text

[SE-0165] DictionaryͱSetͷڧԽ 1. Merging initializers and methods 2. Key-based subscript with default value 3. Dictionary-specific map and filter 4. Visible dictionary capacity 5. Grouping sequence elements 6. Apply relevant changes to Set

Slide 8

Slide 8 text

1. Merging initializers and methods SKIP

Slide 9

Slide 9 text

2. Key-based subscript with default value let source = "how now brown cow" var frequencies: [Character: Int] = [:] for c in source.characters { if frequencies[c] == nil { frequencies[c] = 1 } else { frequencies[c]! += 1 } } ●มߋલ

Slide 10

Slide 10 text

2. Key-based subscript with default value let source = "how now brown cow" var frequencies: [Character: Int] = [:] for c in source.characters { frequencies[c, default: 0] += 1 } ●มߋޙ σϑΥϧτ஋ͷઃఆ͕Մೳʹ

Slide 11

Slide 11 text

3. Dictionary-specific map and filter let numbers = ["one": 1, "two": 2, "three": 3, "four": 4] let evens = Dictionary(numbers.lazy.filter { $0.value % 2 == 0 })! // ["four": 4, "two": 2] let strings = Dictionary(numbers.lazy.map { (k, v) in (k, String(v)) })! // ["three": "3", "four": "4", "one": "1", "two": "2"] ●มߋલ

Slide 12

Slide 12 text

3. Dictionary-specific map and filter let strings = numbers.mapValues(String.init) // ["three": "3", "four": "4", "one": "1", "two": "2"] ●มߋޙ 1. keyΛҡ࣋ͨ͠৽͍͠DictionaryΛฦ͢mapValues let strings = Dictionary(numbers.lazy.map { (k, v) in (k, String(v)) })! // ["three": "3", "four": "4", "one": "1", "two": "2"]

Slide 13

Slide 13 text

3. Dictionary-specific map and filter ●มߋޙ 2. DictionaryΛฦ͢filter let evens = numbers.filter { $0.value % 2 == 0 } // ["four": 4, "two": 2] let evens = Dictionary(numbers.lazy.filter { $0.value % 2 == 0 })! // ["four": 4, "two": 2]

Slide 14

Slide 14 text

4. Visible dictionary capacity var numbers = ["one": 1, "two": 2, "three": 3, "four": 4] numbers.capacity // 6 numbers.reserveCapacity(20) numbers.capacity // 24 ●มߋޙ DictionaryͷcapacityΛ֬ೝͨ͠Γɺ༧໿Ͱ͖Δ

Slide 15

Slide 15 text

5. Grouping sequence elements let names = ["Patti", "Aretha", "Anita", "Gladys"] // By first letter Dictionary(grouping: names, by: { $0.characters.first! }) // ["P": ["Patti"], "G": ["Gladys"], "A": ["Aretha", "Anita"]] // By name length Dictionary(grouping: names) { $0.utf16.count } // [5: ["Patti", "Anita"], 6: ["Aretha", "Gladys"]] ●มߋޙ Dictonaryͷάϧʔϐϯά͕Մೳ

Slide 16

Slide 16 text

6. Apply relevant changes to Set ●มߋޙ Setʹ΋ҎԼΛ௥Ճ ɾSetΛฦ͢filterϝιου struct Set { func filter(_ isIncluded: (Element) throws -> Bool) rethrows -> Set var capacity: Int { get } var reserveCapacity(_ capacity: Int) } ɾcapacity, reserveCapacityϓϩύςΟͷ௥Ճ

Slide 17

Slide 17 text

[SE-0174] Change filter to return an associated type ●มߋલ ɾDictionaryͷfilter͸DictionaryΛฦ͢ˠ ref:SE-0165 ɾଞͷCollectionͷfilter͸[Element]Λฦ͢ˠ ɾDictionaryͷfilter͸DictionaryΛฦ͢ͷʹɺ ଞͷCollectionͷfilter͸[Element]Λฦ͢ʁʁʁ →Genericsʹ·ͱΊΒΕ·ͤΜʁ

Slide 18

Slide 18 text

[SE-0174] Change filter to return an associated type ●มߋޙ Sequenceͷfilter͸ؔ࿈ܕFilteredΛฦ͢ let cast = ["Vivien", "Marlon", "Kim", "Karl"] let shortNames = cast.filter { $0.characters.count < 5 } print(shortNames) // Prints "["Kim", "Karl"]" protocol Sequence { associatedtype Filtered func filter( _ isIncluded: (Iterator.Element) throws -> Bool ) rethrows -> Filtered }

Slide 19

Slide 19 text

[SE-0170] NSNumber bridging and Numeric types let n1 = NSNumber(value: UInt32(543)) let v1 = n1 as? UInt32 // 543 let v2: UInt32 = 543 let n2 = v2 as NSNumber // 543 let n3 = NSNumber(value: UInt32(543)) let v3 = n3 as Int16 // 543 let n4 = NSNumber(value: UInt32(543)) let v4 = n4 as? Int8 // 31 let v5 = Int8(NSNumber(value: Int64.max)) // -1 ●มߋલ Ωϟετͷڍಈ͕͓͔͍͠

Slide 20

Slide 20 text

[SE-0170] NSNumber bridging and Numeric types let n1 = NSNumber(value: UInt32(543)) let v1 = n1 as? UInt32 // 543 let v2: UInt32 = 543 let n2 = v2 as NSNumber // 543 let n3 = NSNumber(value: UInt32(543)) let v3 = n3 as Int16 // 543 let n4 = NSNumber(value: UInt32(543)) let v4 = n4 as? Int8 // nil let v5 = Int8(NSNumber(value: Int64.max)) // nil ●มߋޙ NSNumberͷCast͸ɺ”͜ͷܕͰදݱͰ͖Δ͔”ͱ͍͏൑ఆ΁

Slide 21

Slide 21 text

String Manifesto

Slide 22

Slide 22 text

[SE-0178] Add unicodeScalars property to Character let ws = CharacterSet.whitespacesAndNewlines s.split { $0.unicodeScalars.contains(where: ws.contains) } ●มߋલ StringͷCharacter͕ϒϥοΫϘοΫεʹͳ͍ͬͯΔ ͜͏͍͏͜ͱͰ͖ͳ͍❌

Slide 23

Slide 23 text

[SE-0178] Add unicodeScalars property to Character extension Character { public struct UnicodeScalarView : BidirectionalCollection { public struct Index public var startIndex: Index { get } public var endIndex: Index { get } public func index(after i: Index) -> Index public func index(before i: Index) -> Index public subscript(i: Index) -> UnicodeScalar } public var unicodeScalars: UnicodeScalarView { get } } ●มߋޙ unicodeScalarsΛ௥Ճ

Slide 24

Slide 24 text

Ownership Manifest

Slide 25

Slide 25 text

೉͍͠

Slide 26

Slide 26 text

No content

Slide 27

Slide 27 text

No content

Slide 28

Slide 28 text

No content

Slide 29

Slide 29 text

No content

Slide 30

Slide 30 text

·ͩಡΜͰ·ͤΜ

Slide 31

Slide 31 text

https://github.com/ omochi/swift-ownership-jp

Slide 32

Slide 32 text

[SE-0173] Add MutableCollection.swapAt(_:_:) while hi != lo { swap(&elements[lo], &elements[hi]) } ●มߋલ Ownership ManifestͰ1ͭͷม਺Λ2ͭͷinoutʹ౉͢ͷ͕ېࢭͱͳͬͨ while hi != lo { elements.swapAt(lo, hi) } ●มߋޙ

Slide 33

Slide 33 text

[SE-0176] Enforce Exclusive Access to Memory

Slide 34

Slide 34 text

[SE-0176] Enforce Exclusive Access to Memory

Slide 35

Slide 35 text

Preview of Next Time 1. About Accepted Proposals • Diff from May 23 - June 18 2. Memory Ownership Manifesto / SE-0176 3. WWDC / AltConf Recap

Slide 36

Slide 36 text

Thank you