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

Swift weekly 2017/12/05

Johnlin
December 05, 2017

Swift weekly 2017/12/05

Johnlin

December 05, 2017
Tweet

More Decks by Johnlin

Other Decks in Programming

Transcript

  1. Swift ࿦ஃ • ໨લ Swift ૬᮫త౼࿦౎ੋࡏ mailing list ্ɻ •

    ༗ᴍ೉၏፺ਘ೭ྨత • ༬ܭ 12 ݄த။Ҡ౸ࣗՍత Discourse ࿦ஃ্ɼ။೺ ᢜత mailing list 㚎༰Ҡաڈ
  2. Evolution • [SE-0187] Ճೖ Sequence.filterMap(_:) • [SE-0188] ᩋ Index Ꮣ੒

    Hashable • [SE-0189] ݶ੍ލ module త Struct init • [SE-0190] ฏ୆൑Ꮧ • [SE-0191] Ҡআ Collection త IndexDistance
  3. [SE-0187] Ճೖ Sequence.filterMap(_:) • ݱࡏSwift ༗ࡾछ flatMap • ୈҰछੋ࠷ৗݟతɼᩋၷ૚త Sequence

    Ꮣ Ұ૚
 let fm1 = [[1,2], [2,3]].flatMap { return $0 } fm1 //[1,2,2,3] • ୈೋछੋሣ Optional ཫ໘తᆴ၏ࣄ
 let opt : Int? = 1 let fm2 = opt.flatMap {return $0 == nil ? nil : $0!+1} // 2 • ୈࡾछੋ༻ိ೺ Seqence ཫ໘త nil ᖤᎃ
 let fm3 = [1,nil,2].flatMap{return $0} // [1,2]
  4. [SE-0187] Ճೖ Sequence.filterMap(_:) • ୈࡾछతߦҝ࿨໊᜝ሣෆىိ
 let fm3 = [1,nil,2].flatMap{return $0}

    // [1,2] • ॴҎཁվ੒࿨ Rust ؐ༗ Ocaml Ұᒬత໊᜝ 
 filterMap • ᢜత။ཹஶɼୠੋ။௓ Warning ࿨ fix-it
  5. [SE-0188] ᩋ Index Ꮣ੒ Hashable • ՄҎ༻Ꮠࣈత key path ኺ

    array ፤౦੢ let numbers = [10, 20, 30, 40, 50] let firstValue = \[Int].[0] print(numbers[keyPath: firstValue]) // 10 • ୠੋ༻ index ။ᆦᎃɼҼҝindex ෆੋ Hashable let string = "Helloooo!" let firstChar = \String.[string.startIndex] // error: subscript index of type 'String.Index' in a key path must be Hashable • ။೺ሏվ੒ Hashable
  6. [SE-0189] ݶ੍ލ module త 
 Struct init • ݱࡏՄҎ༻ extension

    㢨ผత module ཫత Struct Ճ init വᏐɼୠੋෆೳ㢨 class Ճ initɻ • ೗Ռ Struct Ճྃ৽త let ᏓᏐɼୠੋ extension ᔒڅ ଞᆴब။ᆦᎃɻ • Ҏޙ㢨ผత module త Struct Ճత init Ұఆཁݺڣ self.init(...)ɼෆવ Swift 4 ။༗ warning, 5 ။ Error
  7. [SE-0190] ฏ୆൑Ꮧ • ݱࡏཁ൑Ꮧੋෆੋ simulator ཁṜᒬሜ #if (arch(i386) || arch(x86_64))

    && (!os(macOS)) print("Simulator") #else print("Device") #endif • ೭ޙՄҎ௚઀༻ #if targetEnvironment(simulator) print("Simulator") #endif
  8. [SE-0191] Ҡআ Collection త IndexDistance • Collection ཫ໘༗Ұݸ associated type

    IndexDistance ༻ိදࣔ index ೭ؒతڑ཭త type • ࡏ 99.999999% త৘گԼ౎ੋ Int • መࡏ༗ᴍແ༻ɼ௚઀ઃ੒ Int
  9. Community • http://dlvm.org/ ׬શ༻ Swift ሜత Deep Learning • Google

    ਖ਼ࡏ։ᚙ Fuchsia ্త Swift https:// www.theverge.com/google/2017/11/20/16681556/ apple-swift-language-google-fuchsia-os-open- source
 https://github.com/apple/swift/pull/12955