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

Codableはイケメン / 20160616 #otemachi_swift

Codableはイケメン / 20160616 #otemachi_swift

Otemachi.swift #01 - WWDC17 振り返り - connpass
https://nikkei.connpass.com/event/58452/
の発表資料です。

# 参考リンク

What's New in Foundation - WWDC 2017 - Videos - Apple Developer
https://developer.apple.com/videos/play/wwdc2017/212/

Swift 4から実装されるCodable/codable_in_foundation_with_swift4 // Speaker Deck
https://speakerdeck.com/fromkk/codable-in-foundation-with-swift4

Decodable - Pairs Taiwan // Speaker Deck
https://speakerdeck.com/muukii0803/decodable-pairs-taiwan

704056da9a4c4e075ad14479beaebab7?s=128

takasek

June 16, 2017
Tweet

Transcript

  1. Codable͜ͱ͸͡Ί by. 2017/6/16 Otemachi.swift #01 1

  2. takasek iOS Developer ϑϦʔϥϯε(΄΅FiNC) @takasek OSS ActionClosurable Notifwift౳ 2

  3. Codable introduced in WWDC2017 https://developer.apple.com/videos/play/wwdc2017/212/ 3

  4. Codable͸ϞςϞς ֤ॴWWDCৼΓฦΓձͰɺ୞ࠓ3೔࿈ଓͷϐοΫΞοϓه࿥थཱத 6/14 AKIBA.swift / by fromkkɹ6/15 eureka Meetup /

    by Muukii ɹ!ͬ͘͟Γ֓ཁ௫ΊΔࢿྉɹɹ!DecodingErrorʹ͍ͭͯৄ͍͠ 4
  5. վ୊ Codable͸Πέϝϯ by. 2017/6/16 Otemachi.swift #01 5

  6. 6

  7. Codable ͷΠέϝϯϙΠϯτ 4 جຊతʹ࢖͍ํ͸ ܕʹ Codable Λ͚ͭΔ͚ͩʂ 4 ͚ͩͲCustomizable 4

    ͲΜͳEncoder/Decoderʹରͯ͠΋ (JSON, Plist, ·ͩݟ͵something...)࠶ར༻Մೳ 7
  8. ʲ༨ஊʳ Decoderͱ͍͑͹ ࣗ࡞ CSVDecoder ͷ࡞ྫ QiitaͰެ։ͯ͠·͢! 8

  9. Ͳ͏customizableͳͷ͔ جຊɺίϯύΠϥ͕ܕͷϝϯόΛࣗಈੜ੒ ※protocol extensionΛར༻ͯ͠Δ = ࣮૷্ॻ͖Մೳ Ωʔ໊ΛΧελϜ͍ͨ͠ʂ ! CodingKeyΛࣗલ࣮૷ σίʔυϩδοΫΛΧελϜ͍ͨ͠ʂ

    ! initΛࣗલ࣮૷ 9
  10. 10

  11. 11

  12. طଘͷSwiftͷ࢓૊ΈΛ ׆༻ͯ͠·͢Ͷʂ ͘ʙʙʙʙʙͬʂ Πέϝϯʂ! 12

  13. ·ͩ·ͩ͋Γ·͢ CodableͷΠέϝϯϙΠϯτ 13

  14. ͍͍ͩͨͷܕ͸Codable ͔ͩΒɺCodableͳܕͷू߹Ͱ͋Δ Ϣʔβʔఆٛܕ΋αΫοͱCodableΕΔ 14

  15. classͷܧঝ΋ߟྀࡁ superdecoder ͰsuperclassΛσίʔυ 15

  16. Date, Data ʹ͍ͭͯɺಈతʹ Encoding StrategiesΛܾΊΒΕΔ ʢ͜Ε͸JSONEncoder/Decoderͷ࿩͚ͩͲʣ 16

  17. Codable Philosophy͸௒Πέϝϯ 4 Error handling built-in 4 ૊Έࠐ·ΕͨΤϥʔ੍ޚ 4 Encapsulate

    encoding details 4 ΤϯίʔσΟϯάͷৄࡉΛΧϓηϧԽ 4 Abstract format from type 4 ந৅Խ͞ΕͨϑΥʔϚοτ 17
  18. Codable Philosophy͸௒Πέϝϯ 4 Error handling built-in 4 ૊Έࠐ·ΕͨΤϥʔ੍ޚ 4 Encapsulate

    encoding details 4 ΤϯίʔσΟϯάͷৄࡉΛΧϓηϧԽ 4 Abstract format from type 4 ந৅Խ͞ΕͨϑΥʔϚοτ 18
  19. Error handling built-in ᶃ ৄࡉͳΤϥʔͰσίʔυ/Τϯίʔυͷࣦഊ Λڭ͑ͯ͘ΕΔ AppleͷϓϨθϯλʔ ʮ༧ظ͠ͳ͍input͸ɺAPIมߋͳͲͰ࣌ʹΑͬͯى͜ Γ͏ΔɻͳͷͰFatalErrorʹ͸͠ͳ͍͜ͱʹܾΊͨʯ Τϥʔͷৄࡉ͸ࡢ೔ͷMuukii͞Μͷࢿྉࢀর

    https://speakerdeck.com/muukii0803/ decodable-pairs-taiwan 19
  20. Error handling built-in ᶄ SwiftͷܕγεςϜͰ͸දݱ͖͠Εͳ͍ υϝΠϯݻ༗ͷόϦσʔγϣϯΛ ΠχγϟϥΠζ࣌ʹ࣮ߦՄೳ 20

  21. σίʔυͷϑΣʔζ 1. σίʔυ 4 όΠτσʔλ 4 ߏ଄Λ࣋ͭόΠτσʔλ (JSON౳) 4 ܕ෇͚͞Εͨσʔλ(Swift

    ͷܕ) 2. όϦσʔγϣϯ 4 Domain-specific validation 4 Graph-level validation 21
  22. 22

  23. URLͷscheme͕ https Ͱ͋Δ͜ͱΛ ܕͱͯ͠ڧ੍Ͱ͖ͨʂ 23

  24. Codable Philosophy 4 Error handling built-in 4 ૊Έࠐ·ΕͨΤϥʔ੍ޚ 4 Encapsulate

    encoding details 4 ΤϯίʔσΟϯάͷৄࡉΛΧϓηϧԽ 4 Abstract format from type 4 ந৅Խ͞ΕͨϑΥʔϚοτ 24
  25. Protocol Orientedͳઃܭ͕Πέϝϯ 25

  26. ͦΜͳϓϩτίϧઃܭͷΠέϝϯͬ΀Γ ΋ͬͱৄ͘͠ޠΓ͍ͨΜͰ͕͢… !" …·ͨผͷػձʹʂ 26