How to Auto call an @IBAction function
doSomeTask(UIButton())
in swift 5.0 and onward
You can either change the signature of the IBAction by making its parameter an Optional like this:
@IBAction func doSomeTask(sender: UIButton?) {
// code
}
and then call it with nil as an argument:
doSomeTask(nil)
Or you can use the IBAction as a wrapper for the real function:
func doSomeTaskForButton() {
// ...
}
@IBAction func doSomeTask(sender: UIButton) {
doSomeTaskForButton()
}
meaning you can then call doSomeTaskForButton()
from wherever you want.