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

How to blink a button iOS swift?

Convert NsNumber, NSDate to String in iOS Swift

Parse the value from string value iOS swift