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

What will be changed in Swift 4(3)

What will be changed in Swift 4(3)

未定

d_date

May 23, 2017
Tweet

More Decks by d_date

Other Decks in Programming

Transcript

  1. 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
  2. [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
  3. 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 } } •มߋલ
  4. 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 } •มߋޙ σϑΥϧτ஋ͷઃఆ͕Մೳʹ
  5. 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"] •มߋલ
  6. 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"]
  7. 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]
  8. 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Λ֬ೝͨ͠Γɺ༧໿Ͱ͖Δ
  9. 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ͷάϧʔϐϯά͕Մೳ
  10. 6. Apply relevant changes to Set •มߋޙ Setʹ΋ҎԼΛ௥Ճ ɾSetΛฦ͢filterϝιου struct

    Set<Element: Hashable> { func filter(_ isIncluded: (Element) throws -> Bool) rethrows -> Set var capacity: Int { get } var reserveCapacity(_ capacity: Int) } ɾcapacity, reserveCapacityϓϩύςΟͷ௥Ճ
  11. [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ʹ·ͱΊΒΕ·ͤΜʁ
  12. [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 }
  13. [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 •มߋલ Ωϟετͷڍಈ͕͓͔͍͠
  14. [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͸ɺ”͜ͷܕͰදݱͰ͖Δ͔”ͱ͍͏൑ఆ΁
  15. [SE-0178] Add unicodeScalars property to Character let ws = CharacterSet.whitespacesAndNewlines

    s.split { $0.unicodeScalars.contains(where: ws.contains) } •มߋલ StringͷCharacter͕ϒϥοΫϘοΫεʹͳ͍ͬͯΔ ͜͏͍͏͜ͱͰ͖ͳ͍❌
  16. [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Λ௥Ճ
  17. [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) } •มߋޙ
  18. Preview of Next Time 1. About Accepted Proposals • Diff

    from May 23 - June 18 2. Memory Ownership Manifesto / SE-0176 3. WWDC / AltConf Recap