In a very basic shaking dice app in Swift 4, I have two functions. The first runs the random dice function. The second however needs a sender argument as it's really an IBAction
so it needs to know which button is being pressed.
How do I add a fake button hit to motionEnded
during the shake?
// MARK: -- Outlets and Actions
@IBOutlet weak var diceImageView1: UIImageView!
@IBOutlet weak var diceImageView2: UIImageView!
@IBAction func rollButtonPressed(_ sender: UIButton) {
updateDiceImages()
updateRollButton(sender)
}
...
override func motionEnded(_ motion: UIEventSubtype, with event: UIEvent?) {
updateDiceImages()
// how to send sender from motionEnded?
rollButtonPressed( magic sender needed )
// or another function that also needs the UIButton sender
updateRollButton( same magic sender needed )
}
}
IBAction
s don't have to have asender
argument, you can remove it.Note that after modifying the function, you should rewire the action inside Interface Builder to prevent crashing.