title: Calculate age from birth date using textfield and NSDateComponents in Swift4
body: <p>I am trying calculate the age from birthday Date in Swift with this function: (want to write in a textField and pass this data from VC in a Label) </p>
  
  <pre><code>{
  var a = self.dob.text
          var c = a!.components(separatedBy: "-")
          var y1 = c[2]
          let cal = NSCalendar? = NSCalendar(calendarIdentifier: .gregorian)
          let now = Date()
          let year = Calendar.components(.year, from: dob!, to: now, options: [])
          let age = (year!) - Int(y1)!
          self.myage.text = String(age)
  
  }
  </code></pre>
  
  <p>But I get an error cannot assign NSCalendar?.Type, but I don't know why get this error (its my first time coding)</p>