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

Swift Weekly 11/1

Johnlin
November 01, 2016

Swift Weekly 11/1

Johnlin

November 01, 2016
Tweet

More Decks by Johnlin

Other Decks in Programming

Transcript

  1. Server API Project • ਪಈލฏ୆త Server Side ጯ༻ɻ • ሡ໢࿏࿨҆શ૬᮫త

    API Ҡ২౸ Swift ɼ ࠶໵ෆ༻ґ ↳֎෦త C ఔࣜݿɻ • ෆ။แؚߴ֊త Server ᐽՍɻ • ݱࡏత໨ඪੋݐཱҰݸᘐཱత౟݅ɼ؃؃੒Ꮘ೗Կ࠶ ܾఆཁෆཁ㚎ݐɻ
  2. Server API workgroup • ֩৺੒һแؚ Chris Bailey (@seabaylea, IBM Kitura),

    Logan Wright (@LoganWright, Vapor), Paulo Faria (@paulofaria, Zewo), Steve Algernon (@salgernon, Apple) • ૬᮫ऀ(stakeholder): ኷ଟਓɼ୞ཁᚙPR बՄҎᙛ૬᮫ऀ • ྲྀఔ:
 API ఏҊ -> ֩৺/૬᮫ऀධ࿦-> Evolution ධ࿦ -> ։ᚙ -> ᚙ෍ -> ࢖༻ -> ճᰶ
  3. Evolution • SE-0141 ࢖༻ @available ိඪࣔ Swift ൛ຊ • SE-0142

    ༻where ိݶ੍ associated types • (佀ճ) SE-0144 Ҹڐ࢖༻ $ ᙛ࡞ identifier
  4. SE-0141 ࢖༻ @available ိඪࣔ Swift ൛ຊ • ݱࡏཁᒾҰ Swift ൛ຊ୞ೳ༻

    #if swift(>=3.0) Ṝछڊ ूɻ • ະိՄҎ༻ @available(swift 3) ိએࠂՄ༻త swift ൛ ຊɻ • ໵ՄҎ༻ @available(swift, obsoleted: 3.1) ိએࠂະိ ။ኑআɻ • ࿨ڊूతࠩҟᴍࡏෆधཁॏ৽ฤᩄɻ
  5. SE-0142 ༻where ိݶ੍ associated types • ՄҎݶ੍ associated type ೭ؒత᮫࿆ੑ

    protocol Sequence { associatedtype Iterator : IteratorProtocol associatedtype SubSequence : Sequence where SubSequence.Iterator.Element == Iterator.Element }
  6. (佀ճ) SE-0144 Ҹڐ࢖༻ $ ᙛ࡞ identifier • աڈ༗Ұݸ Bug ੋՄҎ༻ᄸҰݸ

    $ ᥒᙛ၏ identifier • ॴҎग़ݱྃҰݸ Lib ڣ၏ dollar ՄҎ၏Ұࠣ Functional తࣄɼ૾ੋ map/reduce • ޙိଞ၇೺Ṝݸ bug म޷ྃɼୠ༗ਓबෆ։৺ྃ • ࠷ޙେՈܾఆෆೳҝྃҰݸ Lib ೺ swift Ꮣಘෳᯑ

  7. ᔟܕ Range ԋࢉ๏ • Swift 3 ༗ၷछ range • Range

    a..<b ෆแؚ b • CloseRange a…b แؚ b • ໰୊ࡏଞ၇೭ؒෆೳޓ૬᫚׵
  8. Range 㚎ᬋػᏐࣈ func random(from range: Range<Int>) -> Int { let

    distance = range.upperBound - range.lowerBound let rnd = arc4random_uniform(UInt32(distance)) return range.lowerBound + Int(rnd) } let random1 = random(from: 1..<10) let random2 = random(from: 1...10) //error
  9. Range 㚎ᬋػᏐࣈ func random(from range: Range<Int>) -> Int { let

    distance = range.upperBound - range.lowerBound let rnd = arc4random_uniform(UInt32(distance)) return range.lowerBound + Int(rnd) } func random(from range: ClosedRange<Int>) -> Int { let distance = range.upperBound - range.lowerBound let rnd = arc4random_uniform(UInt32(distance)) return range.lowerBound + Int(rnd) } let random1 = random(from: 1..<10) let random2 = random(from: 1...10)
  10. ׵Ұݸ૝๏ extension RandomAccessCollection { func random() -> Iterator.Element? { guard

    count > 0 else { return nil } let offset = arc4random_uniform(numericCast(count)) let i = index(startIndex, offsetBy: numericCast(offset)) return self[i] } } (1..<10).random() (1...20).random() ["a","b","c","d"].random()