Добрый день! подскажите как грамотно сделать в коде есть расширение
extension Date {
func allDates(till endDate: Date) -> [Date] {
var date = self
var array: [Date] = []
while date <= endDate {
array.append(date)
date = Calendar.current.date(byAdding: .day, value: 1, to: date)!
}
//print (array)
return array
}
func dateFormatString (_ dateString: [Date] ) -> String {
let fmt = DateFormatter()
fmt.dateFormat = "MMM d"
var da = ""
for i in dateString {
da = fmt.string(from: i)
print (da)
}
return da
}
}
получаю массив дат за 20 дней
if let date = Calendar.current.date(byAdding: .day, value: 20, to: Date()) { print(Date().dateFormatString(Date().allDates(till: date))) }
print Sep 12
Sep 13
Sep 14
Sep 15
Sep 16
Sep 17
Sep 18
Sep 19
Sep 20
Sep 21
Sep 22
Sep 23
Sep 24
Sep 25
Sep 26
Sep 27
Sep 28
Sep 29
Sep 30
Oct 1
Oct 2
эти данные нужно добавить CollectionView. Вопрос куда нужно добавить полученный результат (массив, структуры или по другому), чтобы потом воспользоваться в func collectionView()