Get the age from birth date iOS swift

 Solution:

The below function will be used for calculate the age based on the birth date iOS swift.

extension Date {

    func findAge() -> String {

        let now = Date()

        let birthday: Date = self

        let calendar = Calendar.current

        

        let ageComponents = calendar.dateComponents([.year], from: birthday, to: now)

        let age = ageComponents.year!

        return String(describing: age)

    }


}

Comments

Popular posts from this blog

Invalid bundle error while upload the app to the app Store

store cgpoint in userdefaults iOS swift