if i have a ViewController, which has an instance ShowAlert. showAlert will show an alert controller, but is there any way the instance showAlert can know about who instantiated it? i.e. is there any way not to pass self to ShowAlert's instance variable viewController and instead infer it by parent or something similar? should i somehow be delegating this, instead?
class ViewController: UIViewController {
var showAlert = ShowAlert()
override viewDidLoad() {
super.viewDidLoad()
showAlert.viewController = self
showAlert.now()
}
}
class ShowAlert: NSObject {
var viewController: UIViewController!
func now() {
let alert = UIAlertController(title: "Title", message: "Message", preferredStyle: .Alert)
viewController.showViewController(alert, sender: self)
}
}
thanks -