Adding arguments to UIAlertAction

293 views Asked by At

I have 2 classes in separate files: lets call them NotificationManagement and NotificationReceiver

in my NotificationReceiver class i have the following code:

 class NotificationReceiver: UIViewController{
 //...   

 func showNotificationHandler(alert: UIAlertAction!) {

        var storyboard : UIStoryboard = UIStoryboard(name: Constants.storyboardName, bundle: nil)
        var vc : Article = storyboard.instantiateViewControllerWithIdentifier(Constants.articleVCTitle) as! Article
        self.presentViewController(vc, animated: false, completion: nil)


    }
    func dismissNotificationHandler(alert: UIAlertAction!) {
        Constants.articleAddress = ""
    }

    func showAlert(title:String, message:String) {

        let alert = UIAlertController(title: title,
            message: message, preferredStyle: .Alert)
        let okAction = UIAlertAction(title: Messages.showMsg, style: .Default , handler: showNotificationHandler)
        let dismissAction = UIAlertAction(title: Messages.discardMsg, style: .Cancel, handler: dismissNotificationHandler)
        alert.addAction(dismissAction)
        alert.addAction(okAction)
        self.presentViewController(alert, animated: false, completion: nil)
        }
  //...
}

Now I want to put handling of this notification in NotificationManagement class instead the NotificationReceiver class. However if I do put it there i need something like that in the handler, to pass the information about current view controller:

func showNotificationHandler(alert: UIAlertAction!, currentViewController: UIViewController) {

        var storyboard : UIStoryboard = UIStoryboard(name: Constants.storyboardName, bundle: nil)
        var vc : Article = storyboard.instantiateViewControllerWithIdentifier(Constants.articleVCTitle) as! Article
        currentViewController.presentViewController(vc, animated: false, completion: nil)  
    }

But then i cant compile and the errors are really misleading like the compiler cannot find style .Default (and its because i added arguments to the showNotificationHandler ). I would like to use the function in NotificationReceiver like this :

let notificationManagement = NotificationManagement()
notificationManagement.showAlert("title",message: "message")
0

There are 0 answers