Re: エラーと警告でコードをデザインする

Re: エラーと警告でコードをデザインする

6a55a7fb19c1fa78e86ddca7a69db088?s=128

Yuka Ezura

March 22, 2017
Tweet

Transcript

  1. 4.

    લఏ struct Object { var name: String var something: Any

    func common() { /* do something */ } func method1() { /* do something */ } func method2() { /* do something */ } }
  2. 7.
  3. 10.

    extension Object where State: Init { func method1() -> Object<State1>

    { /* do something */ } } extension Object where State: State1 { func method2() -> Object<State2> { /* do something */ } } func accept(_ object: Object<State2>) { /* do something */ }
  4. 11.

    ࣮૷ͷ֓೦ਤ instance Init state instance State1 instance State2 func method1

    func method2 Object<Init> Object<State1> Object<State2>
  5. 13.

    extension Object where State: Init { func method1() -> Object<State2>

    { let object = Object<State2>(…) // Object ͷϓϩύςΟΛҾ͖ܧ͗ return object } }
  6. 15.

    Object<Init> ͔Β Object<State1> ΁
 σʔλΛҾ͖ܧ͙ʹ͸ʁʁ new.name = self.name new.something =

    self.something struct Container { var name: String var something: Any }
  7. 17.

    Object<Init> ͔Β Object<State1> ΁ extension Object where State: Init {

    func method1() -> Object<State2> { let object = unsafeBitCast(self, to: Object<State2>.self) // do something return object } } Object<Init> ͔Β Object<State1> ΁ Cast
  8. 21.

    extension Object where State: Init { init(name: String, something: Any)

    { self.name = name self.something = something } } State ͕ Init ͷͱ͖ͷΈ
 ίϯετϥΫλΛએݴ
  9. 22.

    let object = Object(name: "sample", something: "something") <Init> ͷ໌͕ࣔෆཁ ஫:

    ͜Ε͕ՄೳͱͳΔ৚͕݅͋Γ·ׂ͕͢Ѫ͠·͢
 (৚͕݅ἧ͍ͬͯͳ͍৔߹ɺίϯύΠϧΤϥʔ)
  10. 25.

    ࢀর • ۽୩ͱ៸໘͕ϓϩάϥϛϯάίʔυͷ಺͔Βௌ͑ͯ͘͜ Δ੠ʹࣖΛ܏ָ͚ͯ͠ΉϥδΦ #9, #14
 http://mookmookradio.com/a0005/ • where Ͱͷܕਪ࿦ͷఏএऀͷํͷ

    gist
 https://gist.github.com/tarunon/ d7071689ab55e29bd367a44833687aa3 • ΤϥʔͱܯࠂͰίʔυΛσβΠϯ͢Δ
 https://speakerdeck.com/ezura/eratojing-gao-de- kodowodezainsuru-chi-tohuang-falselun-wu-qu