Created
December 14, 2020 08:35
-
-
Save AndreyAnt/233c90616c1adc8ee91af8571473df76 to your computer and use it in GitHub Desktop.
Combine, Lesson 5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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