Swift Memory Management: Storing func in var

牧云@^-^@ 提交于 2019-12-03 14:49:41

Couldn't you do something like this:

class mainClass {
    var iVar: iVarClass
    init(iVar:iVarClass){
        self.iVar = iVar
        func go() {
            self.doSomething()
        }
        iVar.callback = go
    }
    func doSomething(){
      self.iVar.jumpUpAndDown?()
    }
}

It is my understanding that this way you wouldn't be capturing self directly and thus would avoid a retain cycle.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!