I have question regarding this piece of code :
func sendDataToBackend() {
Alamofire.request(MoneyCupUsersBackEndRouter.sendBI(BudgetInsightConnectionData(budgetInsightResponse: (self.BudgetInsightJSON)!, budgetInsightPermanentToken: (self.permanentToken)!, srcDate: userData!.lastUpdatedAt))).validate().responseString
{ [weak self] response in
switch response.result{
case .success( _):
DispatchQueue.main.async {
SVProgressHUD.dismiss()
_ = self?.navigationController?.popToRootViewController(animated: true)
}
case .failure(let error):
self?.showError(title: "ERROR SENT DATA BACKEND", message: "Erreur lors de l'envoi des données au Backend", error: error)
}
}
}
func showError(title: String, message: String, error: Error) {
print(title)
print(error)
DispatchQueue.main.async {
SVProgressHUD.dismiss()
let alert = UIAlertController(title: "erreur", message: message, preferredStyle:.actionSheet)
alert.addAction(UIAlertAction(title: "OK", style: .default)
{ Void in
_ = self.navigationController?.popToRootViewController(animated: true)}
)
self.present(alert, animated: true, completion: nil)
}
}
The function showError is called in a closure. But the function also deals with the self object. Since the showError is called within the closure, am I creating a strong reference to self with the call ? If so, I do I get around the problem ?