title: Creating a Countdown Timer in Swift
body: <p>I have wrote this code which counts down to a specific date.</p>
  
  <p>How would I make it so that each element of the countdown is shown in a separate label.</p>
  
  <p>So I would have a label that shows the number of days, a label to show the number of hours, a label to show the number of minutes and a label to show the number of seconds.</p>
  
  <p>Code:</p>
  
  <pre><code>class ViewController: UIViewController {
  
  @IBOutlet weak var dateLabelOutlet: UILabel!
  
  let currentDate = Date()
  let dateFormatter = DateFormatter()
  
  let userCalendar = Calendar.current
  
  let requestedComponent: Set&lt;Calendar.Component&gt; = [.day,.hour,.minute,.second]
  
  override func viewDidLoad() {
      super.viewDidLoad()
      // Do any additional setup after loading the view, typically from a nib.
      let timer = Timer.scheduledTimer(timeInterval: 1.0, target: self, selector: #selector(printTime), userInfo: nil, repeats: true)
      timer.fire()
  
  }
  
  func printTime()
  {
      dateFormatter.dateFormat = "dd/MM/yy hh:mm:ss"
      let startTime = Date()
      let endTime = dateFormatter.date(from: "25/12/16 00:00:00")
      let timeDifference = userCalendar.dateComponents(requestedComponent, from: startTime, to: endTime!)
  
      dateLabelOutlet.text = "\(timeDifference.day!) Days \(timeDifference.hour!) Hours \(timeDifference.minute!) Minutes \(timeDifference.second!) Seconds"
  }
  
  override func didReceiveMemoryWarning() {
      super.didReceiveMemoryWarning()
      // Dispose of any resources that can be recreated.
  }
  </code></pre>
  
  <p>}</p>