-1

What I am intended to do is that, I have one button which triggers two labels. Two labels are initially hidden. I wanted one to appear right away, and the other seconds later when the button is clicked.

What can I add to make this happen?

@IBOutlet var noDelayLabel: UILabel!
@IBOutlet var delayLabel: UILabel!
@IBAction func delayButton(_ sender: Any) {
    noDelayLabel.isHidden = false
    delayLabel.isHidden = false
}
Cœur
  • 37,241
  • 25
  • 195
  • 267
  • This is a duplicate of : https://stackoverflow.com/questions/28821722/delaying-function-in-swift and https://stackoverflow.com/questions/24034544/dispatch-after-gcd-in-swift – Axel Guilmin Feb 27 '17 at 15:15

1 Answers1

1
@IBAction func delayButton(_ sender: Any) {
    noDelayLabel.isHidden = false
    DispatchQueue.main.asyncAfter(
        deadline: DispatchTime.now() + \*delay value here*\}, 
        execute: {
            self.delayLabel.isHidden = false
        }
    )
}
dmorrow
  • 5,152
  • 5
  • 20
  • 31
  • Please flag duplicate questions as duplicates instead of answering with duplicate content. This answer already exists all over the place. – Eric Aya Feb 27 '17 at 15:15