Skip to content

Instantly share code, notes, and snippets.

@owenzhao
Last active January 15, 2017 12:55
Show Gist options
  • Save owenzhao/1933091a01560a5f521643a9a257741c to your computer and use it in GitHub Desktop.
Save owenzhao/1933091a01560a5f521643a9a257741c to your computer and use it in GitHub Desktop.
delay
@IBAction func printHello(_ sender: Any) {
// 延迟
if shouldWaitSwitch.isOn {
Timer.scheduledTimer(withTimeInterval: 0.5, repeats: true, block: { [unowned self] (timer) in
if self.shouldWaitSwitch.isOn { return }
print("你好!")
timer.invalidate()
})
}
else {
print("你好!")
}
}
@IBOutlet weak var shouldWaitSwitch: UISwitch!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment