エラーと警告で
コードをデザインする
~赤と黄の輪舞曲~

6a55a7fb19c1fa78e86ddca7a69db088?s=47 Yuka Ezura
August 20, 2016

 エラーと警告で
コードをデザインする
~赤と黄の輪舞曲~

iosdc での発表資料です

6a55a7fb19c1fa78e86ddca7a69db088?s=128

Yuka Ezura

August 20, 2016
Tweet

Transcript

  1. έϮ⑲ͺ๱ຓ͹
 θ⑲ώΤόλΩϸͫΝ
 _᧬ͺԫ΀ᇷዛູ_ 2016/8/20 ezura

  2. FSSPS΁͜ṽ͟͹ͫ͝Ħ

  3. XBSOJOH΁͜ṽ͟͹ͫ͝Ħ

  4. None
  5. None
  6. None
  7. Δͩ׎͘ͼΛj

  8. Δ͵ͺ᪇͡ ཱͺᲇձ͖ͱ͝͵ͱj

  9. ဒᘥ ࣮ḝ ᙉණ

  10. ͹͟ΝĈ ᦉᷯΔ͔Ν

  11. ࣮ḝ᧸ͽុΜΤ᧬ͺԫᓸ͹
 ᓸ᏶ͣ͸ΑΐͩΙ͘

  12. έϮ⑲ͺ๱ຓ͹
 θ⑲ώΤόλΩϸͫΝ
 _᧬ͺԫ΀ᇷዛູ_

  13. ↟1IBOUPN5ZQF ↟%FDMBSBUJPO"UUSJCVUFT

  14. $BTF

  15. class HogeOperation { /// Ұ౓͚ͩݺͿ͜ͱ func prepare() /// prepare ޙ͔Β࢖͑Δ

    func execute() /// ͍ͭݺΜͰ΋ྑ͍ func mob() }
  16. /// Ұ౓͚ͩݺͿ͜ͱ
 /// prepare ޙ͔Β࢖͑Δ

  17. private var isPrepared = false /// Ұ౓͚ͩݺͿ͜ͱ func prepare() {

    guard !isPrepared else {
 fatalError("prepare() Λෳ਺ݺ͹ͳ͍͜ͱ") } isPrepared = true }
  18. None
  19. None
  20. όλΩϸͩΚ͘Ĉ

  21. 1IBOUPN5ZQF ܕ৘ใΛར༻ͯ͠ॲཧͷޡΓΛࢦఠՄೳʹ

  22. ᴰᨷ΀ঢ়Ừ͹΀Α
 ᑿᠭ൱ၙͼϦςψώΤᨷᤅ

  23. protocol OperationState {} class Init: OperationState {} class Prepared: OperationState

    {}
  24. class HogeOperation<State: OperationState> {}

  25. extension HogeOperation where State: Init { /// Ұ౓͚ͩݺͿ͜ͱ func prepared()

    -> HogeOperation<Prepared> { let readyOp = HogeOperation<Prepared>() 
 // TODO: ඞཁͳσʔλΛҾ͖ܧ͗ return readyOp } }
  26. θϸϖΩϰέϮ⑲ ỹ኷ ỹ኷

  27. None
  28. extension HogeOperation where State: Prepared { /// prepare ΛݺΜͩޙ͔Β࢖༻Մೳ func

    execute() { /* do somethig */ } }
  29. θϸϖΩϰέϮ⑲

  30. ଓ͟΁8FC͹ https://gist.github.com/ezura/ f5aebef7bb86edbfd40b0bd1d0435e00

  31. 1IBOUPN5ZQF͖Ο͖Ο ↟ 'VODUJPOBM4OJQQFU1IBOUPN5ZQFT ↟ 4XJGU.POFZXJUI1IBOUPN5ZQFT ↟ 4XJGU͹1IBOUPN5ZQF ᢮ྶṞ  ↟

    1IBOUPN5ZQF͹θϸϖΩϰᙉͽঢ়ᴋφάψδͫΝ TIJCVZBTXJGU ↑ ঢ়ଶભҠΛ៉ྷʹදݱ͍ͯͯ͠௒ײಈ
  32. $BTF

  33. /// ୅ΘΓʹ fuga Λ࢖͏͜ͱʂ func hoge() { … }

  34. όλΩϸͩΚ͘Ĉ

  35. %FDMBSBUJPO "UUSJCVUFT ৘ใΛ෇༩

  36. /// ୅ΘΓʹ fuga() Λ࢖͏͜ͱʂ @available(*, unavailable,
 message="͓໾ޚ໔͞…(ƅωƅ)",
 renamed="fuga") func hoge()

    { … }
  37. /// ୅ΘΓʹ fuga() Λ࢖͏͜ͱʂ @available(*, unavailable,
 message="͓໾ޚ໔͞…(ƅωƅ)",
 renamed="fuga") func hoge()

    { … }
  38. /// ୅ΘΓʹ fuga() Λ࢖͏͜ͱʂ @available(iOS, deprecated=1,
 message="͓໾ޚ໔͞…(ƅωƅ)",
 renamed="fuga") func hoge()

    { … }
  39. ᬋණ ↟ !BWBJMBCMF ↟ !EJTDBSEBCMF3FTVMU 4XJGU͝Λ  ↟ !XBSO@VOVTFE@SFTVMU 4XJGU͹ഇᬬ

    ஫: Swift3 ͔ΒҰ෦࢓༷͕มߋ͞Ε·͢
  40. ᓸ᏶ͣ͸
 ͖ͣͯ͘͹ͫ͝Ħ

  41. ͦਗ਼ௌ͔Μ͞ͺ͖ͦͨ͘ΐͩͱĈ