Skip to content

Instantly share code, notes, and snippets.

@stevencurtis
Created May 9, 2020 12:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stevencurtis/81b4fea34d7eef5fc5a756a074debba4 to your computer and use it in GitHub Desktop.
Save stevencurtis/81b4fea34d7eef5fc5a756a074debba4 to your computer and use it in GitHub Desktop.
shakevc
class ViewController: UIViewController {
@IBOutlet weak var shakeLabel: UILabel!
var shakeCounter = 0
override func viewDidLoad() {
super.viewDidLoad()
shakeLabel.text = "Shaken 0 times"
}
override func becomeFirstResponder() -> Bool {
return true
}
override func motionEnded(_ motion: UIEvent.EventSubtype, with event: UIEvent?) {
if motion == .motionShake {
shakeCounter += 1
shakeLabel.text = "Shaken \(shakeCounter) times"
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment