Escaping Closures in Swift - 公司內分享會

481a04548eda340e5cf166b487792ee5?s=47 Li-Hsuan Chen
September 23, 2016

Escaping Closures in Swift - 公司內分享會

481a04548eda340e5cf166b487792ee5?s=128

Li-Hsuan Chen

September 23, 2016
Tweet

Transcript

  1. 5.

    class A { func someMethod(closure: () -> Void) { closure()

    } } 鸏♧媯♶剚剤DPNQJMFSFSSPS
  2. 7.

    class A { var closures: [() -> Void]? = []

    func someMethod(closure: () -> Void) { self.closures?.append(closure) } } 㖈4XJGUⴀ⢵⟃⵹鸏媯♶剚剤㉏겗
  3. 8.

    class A { var closures: [() -> Void]? = []

    func someMethod(closure: () -> Void) { self.closures?.append(closure) } }
  4. 9.
  5. 10.

    class A { var closures: [() -> Void]? = []

    func someMethod(closure: @escaping () -> Void) { self.closures?.append(closure) } }
  6. 14.

    class B { var closures: [() -> Void]? = []

    func anotherMethod(closure: @escaping () -> Void) { self.closures?.append(closure) } }
  7. 15.

    class A { func someMethod(closure: () -> Void) { B().anotherMethod(closure:

    closure) } } class B { var closures: [() -> Void]? = [] func anotherMethod(closure: @escaping () -> Void) { self.closures?.append(closure) } } 㖈4XJGUⴀ⢵⟃⵹鸏垺㻨♶剚剤㉏겗
  8. 16.

    class A { func someMethod(closure: () -> Void) { B().anotherMethod(closure:

    closure) } } class B { var closures: [() -> Void]? = [] func anotherMethod(closure: @escaping () -> Void) { self.closures?.append(closure) } }
  9. 17.
  10. 18.

    class A { func someMethod(closure: @escaping () -> Void) {

    B().anotherMethod(closure: closure) } } class B { var closures: [() -> Void]? = [] func anotherMethod(closure: @escaping () -> Void) { self.closures?.append(closure) } }
  11. 22.

    Ⱖ➮ ˖ 〳⟃鍑对SFUBJODZDMF涸㉏겗 4&  䖊㻜뀿  ˖ OPFTDBQFDMPTVSFTIBWFBMTPBMXBZTCFFOUIF QSFGFSSFEEFGBVMU

    TJODFUIFZFMJNJOBUFBDMBTT PGSFUBJODZDMFJTTVFT ˖ QSPUPDPM涸㹁纏 ˖ 㥶卓㻜⡲QSPUPDPM涸倰岁儘꨾銴⸈!FTDBQJOH  QSPUPDPM⚥鑪倰岁涸㹁纏⛳銴⸈♳
  12. 23.