Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do I need [unowned self] in AlamoFire, or is it already taken care of?

        let parameters = [
            "access_token": access_token,
        ]
        self.alamoFireManager!.request(.POST, CONSTANTS.APIEndpoint+"/auth", parameters: parameters).responseJSON { [unowned self]
            response in
            self.startWorking()
        }

Do I need unowned self inside the closure, or is it already taken care of by the library?

like image 563
TIMEX Avatar asked Nov 08 '22 19:11

TIMEX


1 Answers

Use Alamofire.request instead of self.alamoFireManager and you are good to go without capturing self. If you really need to use self.alamoFireManager, as @Tapani mentioned, since alamoFireManager is a property of self, you need to capture self and use [weak self] in the closure

I was looking for the same answer you were looking for. I've found this answer. It mentions about an article about retain cycles. I think you don't need to capture self here.

like image 191
osrl Avatar answered Nov 27 '22 05:11

osrl