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

Swift weekly 2018/04/03

Johnlin
April 03, 2018

Swift weekly 2018/04/03

Johnlin

April 03, 2018
Tweet

More Decks by Johnlin

Other Decks in Programming

Transcript

  1. Swift 4.1 & Xcode 9.3 • Conditional Conformance • Auto

    Equatable & Hashable • xccov : command line parser for Xcode coverage report.
  2. Evolution • [SE-0199] Adding toggle to Bool • [SE-0194] Derived

    Collection of Enum Cases • [SE-0193] Cross-module inlining and specialization • [SE-0143] (मվ) Conditional Conformance
  3. [SE-0194] Derived Collection of Enum Cases • ৗৗ။۰౸धཁ iterate Enum

    ཫ໘㑌Ұݸ case త৘ گɻൺํ㘸૾ੋ๾ࠀṛతՖ৭ɻ • ݱࡏ୞ೳ༻ enum Suit : Int {} ࠶ኺᏐࣈိҰݸݸճਪ
  4. [SE-0194] Derived Collection of Enum Cases • ೭ޙՄҎ༻
 enum Suit

    : CaseIterable {case heart, spade, diamond, club} • बՄҎ፤౸ॴ༗తՖ৭
 Suit.allCases //[heart, spade, diamon, club] • ෆաલఏੋ case ෆೳ༗ attribute, rectangle(5,6)
  5. [SE-0193] Cross-module inlining and specialization // library public func mul(_

    a:Int, _ b:Int) -> Int { return a * b } // user func mul(_ a:Int,_ b:Int,_ c:Int) -> Int { return mul(mul(a,b),c) } • Ҽҝੋࡏෆಉత໛૊ॴҎᔒ㭎๏࠷ՂԽɼ୞ೳরզ၇ ሜతฤᩄ
  6. [SE-0193] Cross-module inlining and specialization // library @_inlineable public func

    mul(_ a:Int, _ b:Int) -> Int { return a * b } // user func mul(_ a:Int,_ b:Int,_ c:Int) -> Int { return mul(mul(a,b),c) // a * b * c } • Ճྃ @inlineable ೭ޙɼฤᩄثबՄҎ፤౸ mul తݪ ࢝ᛰိ၏࠷ՂԽ
  7. [SE-0193] Cross-module inlining and specialization @usableFromInline func add(_ a:Int, _

    b: Int) -> Int { return a + b } @inlineable public func mul(_ a:Int, _ b:Int) -> Int { var res = 0 for _ in 0..<a { res = add(res, b) } return res } • ෆա public ༗Մೳ။ݺڣଖଞവᏐɼ೗ՌṜࠣവᏐ໵૝ ࠷ՂԽɼबधཁՃ @usableFromInline
  8. [SE-0143] (मվ) Conditional Conformance • Conditional Conformance Ҹڐ generic ࡏ

    ᑍ݅ූ߹ తܗگԼ९॥๭ࠣ protocolɻ • Ꭿྫိ㘸ɼ let a = [[1]] let b = [[2]] a == b • ࡏ4.0 ။ᔒ㭎๏ compileɼࡏ 4.1 ੋ false
  9. [SE-0143] (मվ) Conditional Conformance • ෆա 4.1 ؐੋෆೳ၏Լ໘Ṝ݅ࣄ let h:

    [[Int] : Int] = [[1]: 1] • Ҽҝ Array ୞༗ conform Equatable, ୠੋཁᙛ Dict key धཁੋ Hashable . • 4.2 ೭ޙबՄҎྃ, Array, Dict, Optional ౎ՄҎɻ
  10. Community • LOLCode literal for swift 
 https://github.com/apple/swift/pull/15664/ files#diff-8ec25bd1041bc5e833d0451725039b7cR 1


    https://forums.swift.org/t/pitch-lolcode/11565 • https://zh.wikipedia.org/zh-tw/LOLCODE