Say I have a custom container view controller (MainViewController) where I do something like this:
- (void)viewDidLoad
{
[super viewDidLoad];
This is a very common pattern. The parent will be the actual instance that will handle the action, by providing a protocol and a default extension.
In Swift 3:
Parent view controller:
protocol SomeProtocol {
func foo()
}
extension ParentViewController: SomeProtocol {
func foo() {
// Parent handles it
}
}
Child view controller:
@IBAction func tapGo(_ sender: Any) {
(parent as? SomeProtocol)?.foo()
}