I have two view controllers, MainVC
and ModalVC
.
When the user taps a button on MainVC
, the modal view controller appears.
The user can then tap another button to dismiss it and return to the main one.
I have tried these two methods and they both accomplish the same thing: they dismiss the modal view controller:
//method 1:
// File: ModalVC.swift
//
@IBAction func dismissTapped() {
self.dismissViewControllerAnimated(false, completion: nil);
}
That works fine as I said, but consider the other method: using delegation to let the main controller do the dismissing:
// method 2: part A
// File: ModalVC.swift
//
protocol ModalVCDelegate {
func modalVCDismissTapped();
}
...
...
...
var delegat:ModalVCDelegate? = nil;
...
...
@IBAction func dismissTapped() {
delegate.modalVCDismissTapped();
}
and on the main view controller custom class file:
// method 2: part B
// File: MainVC.swift
class MainVC : UIViewController, ModalVCDelegate {
...
...
func modalVCDismissTapped() {
self.dismissViewControllerAnimated(false, completion: nil);
}
}
Since these two methods do the needful, should I worry about any possible memory leakage?
Any explanation would help