I'm working with an app thau use NSDate, it's an app that will be only available for people who has more tha 13 years, so what I want to do is setup the date from the actual date, I mean today but I want to setup the year to 2004 so when I launch the app should appear the actual date, the actual month but the year should be 2004. Right now if the user select a date under 2004 an alert appears, I want to disable this alert and setup the 2004 as default year and then be able to move to any year that the user wants. I'm working with I let the code to validate the year and the code to set the current date, hope you can help me
func validateDate () {
let date = Calendar.current.date(byAdding: .year, value: -13, to: Date())
if selectedDate == nil {
selectedDate = Date()
}
func changeDateToString (date:Date) -> String {
let calendar = Calendar.current
let comp = calendar.dateComponents([.month, .day], from: date)
let year : Int = comp.year!
let month : Int = comp.month!
let day : Int = comp.day!
var stringDay: String = "\(day)"
var stringMonth: String = "\(month)"
let stringYear: String = "\(year)"
if stringDay.characters.count == 1 {
stringDay.insert("0", at: stringDay.startIndex)
}
if stringMonth.characters.count == 1 {
stringMonth.insert("0", at: stringMonth.startIndex)
}
let finalString = stringYear + stringMonth + stringDay + " "
print(finalString)
return finalString
}