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

store cgpoint in userdefaults iOS swift

libc++abi: terminating due to uncaught exception of type NSException iOS swift