Age calculator in iOS swift

 Solution:

        let gregorian = NSCalendar(calendarIdentifier: NSCalendar.Identifier.gregorian)!

        let age = gregorian.components([.year], from: datePicker.date, to: currentDate as Date, options: [])

        

        print(age.year)


You can print the age based on the date picked in date picker using the above method.

Comments

Popular posts from this blog

Invalid bundle error while upload the app to the app Store

Convert NsNumber, NSDate to String in iOS Swift

Global LocationManager Singleton class iOS Swift