title: Calculate age from birth date
body: <p>I cant find age in from birth date. What I got is </p>
  
  <pre><code>fatal error: unexpectedly found nil while unwrapping an Optional value
  (lldb) 
  </code></pre>
  
  <p>My code</p>
  
  <pre><code>override func viewDidLoad() {
          super.viewDidLoad()
  var dateString = user.birthday
          var dateFormatter = NSDateFormatter()
          // this is imporant - we set our input date format to match our input string
          dateFormatter.dateFormat = "dd-MM-yyyy"
          // voila!
          var dateFromString = dateFormatter.dateFromString(dateString)
  
          let age = calculateAge(dateFromString!)
  }
  
  func calculateAge (birthday: NSDate) -&gt; NSInteger {
  
          var userAge : NSInteger = 0
          var calendar : NSCalendar = NSCalendar.currentCalendar()
          var unitFlags : NSCalendarUnit = NSCalendarUnit.CalendarUnitYear | NSCalendarUnit.CalendarUnitMonth | NSCalendarUnit.CalendarUnitDay
          var dateComponentNow : NSDateComponents = calendar.components(unitFlags, fromDate: NSDate())
          var dateComponentBirth : NSDateComponents = calendar.components(unitFlags, fromDate: birthday)
  
          if ( (dateComponentNow.month &lt; dateComponentBirth.month) ||
              ((dateComponentNow.month == dateComponentBirth.month) &amp;&amp; (dateComponentNow.day &lt; dateComponentBirth.day))
              )
          {
              return dateComponentNow.year - dateComponentBirth.year - 1
          }
          else {
              return dateComponentNow.year - dateComponentBirth.year
          }
      }
  </code></pre>