title: Calculate age from birth date using NSDateComponents in Swift
body: <p>I am trying calculate the age from birthdayDate in Swift with this function: </p>
  
  <pre><code>var calendar : NSCalendar = NSCalendar.currentCalendar()
  
  var dateComponentNow : NSDateComponents = calendar.components(
               NSCalendarUnit.CalendarUnitYear, 
               fromDate: birthday, 
               toDate: age, 
               options: 0)
  </code></pre>
  
  <p>But I get an error <code>Extra argument toDate in call</code></p>
  
  <p>In objective c this was the code, but I don't know why get this error:</p>
  
  <pre><code>NSDate* birthday = ...;
  
  NSDate* now = [NSDate date];
  NSDateComponents* ageComponents = [[NSCalendar currentCalendar] 
                                 components:NSYearCalendarUnit 
                                 fromDate:birthday
                                 toDate:now
                                 options:0];
  NSInteger age = [ageComponents year]; 
  </code></pre>
  
  <p>Is there correct form better than this?</p>