Skip to content

Instantly share code, notes, and snippets.

@AndreyAnt
Created December 14, 2020 08:35
Show Gist options
  • Save AndreyAnt/233c90616c1adc8ee91af8571473df76 to your computer and use it in GitHub Desktop.
Save AndreyAnt/233c90616c1adc8ee91af8571473df76 to your computer and use it in GitHub Desktop.
Combine, Lesson 5
@IBAction func actionButton(_ sender: UIButton) {
if state == 0 {
state = 1
Timer.publish(every: TimeInterval(0.2), on: RunLoop.main, in: .default)
.autoconnect()
.sink(receiveValue: { [weak self] text in
self?.button1.text = self!.emoji.emojiArray.randomElement()
self?.button2.text = self!.emoji.emojiArray.randomElement()
self?.button3.text = self!.emoji.emojiArray.randomElement()
})
.store(in: &subscriptions)
} else {
state = 0
// Timer.invalidate(timer)
// timer.connect().cancel()
subscriptions = []
print(button1.text!)
print(button2.text!)
print(button3.text!)
if button1.text == button2.text {
let alert = UIAlertController(title: "Поздравляем", message: "Вы выиграли", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "Yes", style: .default, handler: nil))
self.present(alert, animated: true, completion: nil)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment