title: Why app crashes if year is less than 1948 or more than 2086?
body: <p>My Xcode app crashes if the user inputs a year below 1948 or for example more than the year 2086 and was wondering if anyone had this issue before and how to resolve?</p>
  
  <p>The user selects their date of birth and the app displays data such as the number of seconds between today's date and their date of birth.</p>
  
  <p>I am new to Xcode (Xcode 8) so still learning. Thanks in advance</p>
  
  <pre><code>@IBAction func clickScreenBtn(_ sender: Any) {
  
  
      let birthDay = UserDefaults.standard.object(forKey: "birthday") as! Date
      var component = NSCalendar.current.dateComponents([.day], from: birthDay, to: Date())
  
  
  
      type = type + 1
  
      switch type {
      case 0:
          unitLabel.text = "Days"
          timeLabel.text = ""
          timeLabel.text = timeLabel.text?.appendingFormat("%d", component.day!)
          break
      case 4:
          type = 0
          unitLabel.text = "Days"
          timeLabel.text = ""
          timeLabel.text = timeLabel.text?.appendingFormat("%d", component.day!)
          break
      case 1:
          component = NSCalendar.current.dateComponents([.hour], from: birthDay, to: Date())
          unitLabel.text = "Hours"
          timeLabel.text = ""
          timeLabel.text = timeLabel.text?.appendingFormat("%d", component.hour!)
          break
      case 2:
          component = NSCalendar.current.dateComponents([.minute], from: birthDay, to: Date())
          unitLabel.text = "Minutes"
          timeLabel.text = ""
          timeLabel.text = timeLabel.text?.appendingFormat("%d", component.minute!)
          break
      case 3:
  
          component = NSCalendar.current.dateComponents([.second], from: birthDay, to: Date())
  
          unitLabel.text = "Seconds"
          timeLabel.text = ""
          timeLabel.text = timeLabel.text?.appendingFormat("%d", component.second!)
  
  
          break
      default:
          break
      }
  }
  </code></pre>
  
  <p>Error:</p>
  
  <pre><code> 0x108142301 &lt;+9425&gt;:  callq  0x1082a95c4               ; symbol stub for: Foundation.Calendar.dateComponents (Swift.Set&lt;Foundation.Calendar.Component&gt;, from : Foundation.Date, to : Foundation.Date) -&gt; Foundation.DateComponents
  0x108142306 &lt;+9430&gt;:  movq   -0x710(%rbp), %rdi
  0x10814230d &lt;+9437&gt;:  movq   %rax, -0x730(%rbp)
  0x108142314 &lt;+9444&gt;:  callq  0x10813d8a0               ; swift_rt_swift_release
  0x108142319 &lt;+9449&gt;:  movq   -0x730(%rbp), %rax
  0x108142320 &lt;+9456&gt;:  movq   %rax, -0x8(%rbp)
  0x108142324 &lt;+9460&gt;:  movq   -0x218(%rbp), %rdi
  0x10814232b &lt;+9467&gt;:  callq  0x10813d8a0               ; swift_rt_swift_release
  0x108142330 &lt;+9472&gt;:  movq   0x1e3081(%rip), %rax      ; (void *)0x000000010e87f068: swift_isaMask
  0x108142337 &lt;+9479&gt;:  movq   -0x168(%rbp), %rdx
  0x10814233e &lt;+9486&gt;:  movq   (%rdx), %rdi
  0x108142341 &lt;+9489&gt;:  andq   (%rax), %rdi
  0x108142344 &lt;+9492&gt;:  movq   %rdi, -0x738(%rbp)
  0x10814234b &lt;+9499&gt;:  movq   %rdx, %rdi
  0x10814234e &lt;+9502&gt;:  movq   -0x738(%rbp), %rax
  0x108142355 &lt;+9509&gt;:  callq  *0x80(%rax)
  0x10814235b &lt;+9515&gt;:  movq   %rax, -0x70(%rbp)
  0x10814235f &lt;+9519&gt;:  movq   -0x230(%rbp), %rax
  0x108142366 &lt;+9526&gt;:  movsd  -0x1d8(%rbp), %xmm0       ; xmm0 = mem[0],zero 
  0x10814236e &lt;+9534&gt;:  movd   %xmm0, %rax
  0x108142373 &lt;+9539&gt;:  cmpq   $0x0, -0x70(%rbp)
  0x108142378 &lt;+9544&gt;:  jne    0x108142409               ; &lt;+9689&gt; at MainViewController.swift
  0x10814237e &lt;+9550&gt;:  movq   -0x230(%rbp), %rax
  0x108142385 &lt;+9557&gt;:  movsd  -0x1d8(%rbp), %xmm0       ; xmm0 = mem[0],zero 
  0x10814238d &lt;+9565&gt;:  movd   %xmm0, %rax
  0x108142392 &lt;+9570&gt;:  movq   -0x230(%rbp), %rax
  0x108142399 &lt;+9577&gt;:  movsd  -0x1d8(%rbp), %xmm0       ; xmm0 = mem[0],zero 
  0x1081423a1 &lt;+9585&gt;:  movd   %xmm0, %rax
  0x1081423a6 &lt;+9590&gt;:  movq   -0x230(%rbp), %rax
  0x1081423ad &lt;+9597&gt;:  movsd  -0x1d8(%rbp), %xmm0       ; xmm0 = mem[0],zero 
  0x1081423b5 &lt;+9605&gt;:  movd   %xmm0, %rax
  0x1081423ba &lt;+9610&gt;:  leaq   0x1b13f9(%rip), %rdi      ; "fatal error"
  0x1081423c1 &lt;+9617&gt;:  movl   $0xb, %eax
  0x1081423c6 &lt;+9622&gt;:  movl   %eax, %esi
  0x1081423c8 &lt;+9624&gt;:  movl   $0x2, %eax
  0x1081423cd &lt;+9629&gt;:  leaq   0x1b13ac(%rip), %rcx      ; "unexpectedly found nil while unwrapping an Optional value"
  0x1081423d4 &lt;+9636&gt;:  movl   $0x39, %edx
  0x1081423d9 &lt;+9641&gt;:  movl   %edx, %r8d
  0x1081423dc &lt;+9644&gt;:  xorl   %edx, %edx
  0x1081423de &lt;+9646&gt;:  movl   %edx, -0x73c(%rbp)
  0x1081423e4 &lt;+9652&gt;:  movl   %eax, %edx
  0x1081423e6 &lt;+9654&gt;:  movl   %eax, %r9d
  0x1081423e9 &lt;+9657&gt;:  movl   $0x0, (%rsp)
  0x1081423f0 &lt;+9664&gt;:  callq  0x1082a95f4               ; symbol stub for: function signature specialization &lt;preserving fragile attribute, Arg[2] = Dead, Arg[3] = Dead&gt; of Swift._fatalErrorMessage (Swift.StaticString, Swift.StaticString, file : Swift.StaticString, line : Swift.UInt, flags : Swift.UInt32) -&gt; Swift.Never
  0x1081423f5 &lt;+9669&gt;:  movq   -0x230(%rbp), %rcx
  0x1081423fc &lt;+9676&gt;:  movsd  -0x1d8(%rbp), %xmm0       ; xmm0 = mem[0],zero 
  0x108142404 &lt;+9684&gt;:  movd   %xmm0, %rcx
  0x108142409 &lt;+9689&gt;:  leaq   -0x70(%rbp), %rax
  0x10814240d &lt;+9693&gt;:  movq   -0x70(%rbp), %rcx
  0x108142411 &lt;+9697&gt;:  movq   %rcx, %rdi
  0x108142414 &lt;+9700&gt;:  movq   %rax, -0x748(%rbp)
  0x10814241b &lt;+9707&gt;:  movq   %rcx, -0x750(%rbp)
  0x108142422 &lt;+9714&gt;:  callq  0x1082a9858               ; symbol stub for: objc_retain
  0x108142427 &lt;+9719&gt;:  leaq   0x1b1398(%rip), %rdi      ; "Seconds"
  </code></pre>