Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save michal-majchrzycki/b7602651488b151c1d1e3ede1646ff42 to your computer and use it in GitHub Desktop.
Save michal-majchrzycki/b7602651488b151c1d1e3ede1646ff42 to your computer and use it in GitHub Desktop.
func arrayOfDates() -> NSArray {
let numberOfDays: Int = 14
let startDate = Date()
let formatter: DateFormatter = DateFormatter()
formatter.dateFormat = "EEE d/M"
let calendar = Calendar.current
var offset = DateComponents()
var dates: [Any] = [formatter.string(from: startDate)]
for i in 1..<numberOfDays {
offset.day = i
let nextDay: Date? = calendar.date(byAdding: offset, to: startDate)
let nextDayString = formatter.string(from: nextDay!)
dates.append(nextDayString)
}
return dates as NSArray
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment