Swift Closures - Capturing self as weak

后端 未结 3 1738
春和景丽
春和景丽 2020-12-29 09:32

I am trying to resolve a closure based strong reference cycle in Swift.
In the code below, object is retained by the owning view controller. ProgressHUD is

3条回答
  •  猫巷女王i
    2020-12-29 10:28

    You stated that progressHUD is retained by the owning view controller (self) and you reference it in your closure...so add it to the capture list and then use the captured variable in the closure as follows:

    object.setCompletionHandler { [weak self] (error) -> Void in
        if(!error){
            self?.tableView.reloadData()
        }
        self?.progressHUD.hide(false)
    }
    

提交回复
热议问题