When I initialise the ABCViewController instance to push this controller, like I did it here.
private func showABCController() {
let storyBoard = UIStoryboard (
name: "PaymentView", bundle: Bundle(for: ABCViewController.self)
)
var abcViewController = storyBoard.instantiateViewController(withIdentifier: "ABCViewController") as! ABCViewController
abcViewController.delegate = self
}
The denit method of the view controller is called just after the delegate is set to self even before I push the view controller :-
//ABCViewController.swift
import UIKit
protocol ABCViewControllerDelegate : class{
func backButtonPressed()
}
class ABCViewController: UIViewController {
weak var delegate : ABCViewControllerDelegate?
override func loadView() {
super.loadView()
print("loadView")
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
deinit {
delegate?.backButtonPressed()
}
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// Get the new view controller using segue.destination.
// Pass the selected object to the new view controller.
}
*/
}
My concern why deinit is called? Here I have observed the other methods such as loadview and viewdidload is not called. So before the controller is loaded into the memory how can it be de-initialised.