Make self weak in methods in Swift

后端 未结 5 2004
遇见更好的自我
遇见更好的自我 2020-12-05 07:06

I have a Swift class that needs to store a table of its own methods. Unfortunately this is causing a reference cycle, because its table retains references to self

5条回答
  •  既然无缘
    2020-12-05 07:58

    wrapped no param function with block

    myCallbacks.append({ [unowned self] in self.myInternalFunction() })
    

    wrapped param function with block

    myCallbacks.append({ [unowned self] page in self.reloadData(page: page) })
    

提交回复
热议问题