Here is my code 

```
import Foundation
import UIKit

class Alert: UIViewController {

class func showAlert(title: String, message: String, buttonTitle: String? = nil, buttonTitle2: String? = nil, sender: UIViewController) -> Int? {
    var flag : Int?
    func yes(){
        flag = 1

    }
    func no(){
        flag = 0

    }
     //= nil  ;
    if objc_getClass("UIAlertController") != nil {
        let alert = UIAlertController(title: title, message: message, preferredStyle: UIAlertControllerStyle.Alert)
        if (buttonTitle != nil){
            alert.addAction(UIAlertAction(title: buttonTitle, style: UIAlertActionStyle.Default, handler: { (action: UIAlertAction!) in
            yes()

        }))
        }
        if (buttonTitle2 != nil)  {
            alert.addAction(UIAlertAction(title: buttonTitle2, style: UIAlertActionStyle.Default, handler: { (action: UIAlertAction!) in
                no()

            }))
        }

        sender.presentViewController(alert, animated: true, completion: nil)

       return flag

    } else {
        let alert = UIAlertView()
        alert.title = title
        alert.message = message
        alert.addButtonWithTitle(buttonTitle)
        alert.addButtonWithTitle(buttonTitle2)
        print("inside Else")

        alert.show()
        return flag
        //make and use a UIAlertView
    }

}

}

```

The problem is that the flag getting returned is always nil to the view controller I call Alert from. I need the flag to return 1 if "yes" is pressed and 0 if "No" is pressed. I have been stuck in this problem for lot of time. Help.