Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I simulate a button press in Swift iOS8 using code

How can I simulate a button press within a View in using Swift. I'm trying to get Calendar permissions and have a function setup to check this authorization when I click the start button this currently runs

@IBAction func start(sender: AnyObject) {
//loads prompt to "Allow" or "Don't Allow" calendar permissions
eventStore.requestAccessToEntityType(EKEntityTypeEvent, completion: handler)

//checkAuth function looks at calendar authorization to get current status 
and then acts accordingly to dismiss View or load Privacy Settings
checkAuth()

}

I need to be able to simulate a button press of the Start button to trigger the start() func once again. The only thing I've found so far seems to be in Objective-C

[buttonObj sendActionsForControlEvents: UIControlEventTouchUpInside];

I'm not familiar with Obj-C and need a way to implement this in Swift if possible...Thanks

like image 338
Jason Z Avatar asked Dec 10 '14 23:12

Jason Z


1 Answers

The Swift translation of:

[buttonObj sendActionsForControlEvents: UIControlEventTouchUpInside];

is:

button.sendActions(for: .touchUpInside)

and it should in fact simulate a button push.

like image 86
Lyndsey Scott Avatar answered Oct 02 '22 05:10

Lyndsey Scott