Swift iOS- How to hide label then make it appear after a certain time period

Lance Samaria picture Lance Samaria · Apr 5, 2017 · Viewed 11.1k times · Source

I have a label that gets hidden when a button is pressed. After a certain time period like 60 secs I want the label to reappear. I'd assume I do that in viewDidAppear, How would i do that?

@IBOutlet weak var myLabel: UILabel!

override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
       //after 60 secs myLabel should reappear
       //self.myLabel.isHidden = false
    }


@IBAction func buttonTapped(_ sender: UIButton){
       self.myLabel.isHidden = true
}

Answer

Max Pevsner picture Max Pevsner · Apr 5, 2017
@IBAction func buttonTapped(_ sender: UIButton){
    self.myLabel.isHidden = true
    DispatchQueue.main.asyncAfter(deadline: .now() + 60) {
        self.myLabel.isHidden = false
    }
}