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
Post a Comment