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

Escaping Closures in Swift - 公司內分享會

Li-Hsuan Chen
September 23, 2016

Escaping Closures in Swift - 公司內分享會

Li-Hsuan Chen

September 23, 2016
Tweet

More Decks by Li-Hsuan Chen

Other Decks in Programming

Transcript

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

    } } 鸏♧媯♶剚剤DPNQJMFSFSSPS
  2. class A { var closures: [() -> Void]? = []

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

    func someMethod(closure: () -> Void) { self.closures?.append(closure) } }
  4. class A { var closures: [() -> Void]? = []

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

    func anotherMethod(closure: @escaping () -> Void) { self.closures?.append(closure) } }
  6. 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ⴀ⢵⟃⵹鸏垺㻨♶剚剤㉏겗
  7. class A { func someMethod(closure: () -> Void) { B().anotherMethod(closure:

    closure) } } class B { var closures: [() -> Void]? = [] func anotherMethod(closure: @escaping () -> Void) { self.closures?.append(closure) } }
  8. 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) } }
  9. Ⱖ➮ ˖ 〳⟃鍑对SFUBJODZDMF涸㉏겗 4&  䖊㻜뀿  ˖ OPFTDBQFDMPTVSFTIBWFBMTPBMXBZTCFFOUIF QSFGFSSFEEFGBVMU

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