Writing handler for UIAlertAction

后端 未结 9 894
北恋
北恋 2020-11-28 05:10

I\'m presenting a UIAlertView to the user and I can\'t figure out how to write the handler. This is my attempt:

let alert = UIAlertController(ti         


        
9条回答
  •  时光取名叫无心
    2020-11-28 05:38

    Functions are first-class objects in Swift. So if you don't want to use a closure, you can also just define a function with the appropriate signature and then pass it as the handler argument. Observe:

    func someHandler(alert: UIAlertAction!) {
        // Do something...
    }
    
    alert.addAction(UIAlertAction(title: "Okay",
                                  style: UIAlertActionStyle.Default,
                                  handler: someHandler))
    

提交回复
热议问题