I have two ViewControllers, FirstViewController
and SecondViewController
. Both have an own Swift file, FirstViewController.swift
and
EDIT: These functions have been revised in swift 3 as follows:
Code in FirstViewController
override function viewDidLoad(){
NotificationCenter.default.addObserver(self, selector: #selector(showAlert), name: NSNotification.Name(rawValue: "showAlert"), object: nil)
}
Code in SecondViewController:
@IBAction func callFunctionInOtherClass(sender: AnyObject) {
NotificationCenter.default.post(name: NSNotification.Name(rawValue: "showAlert"), object: nil)
}