Im trying to create a function that receives:
-An StartDate (DATE).
-An EndDate (DATE).
Capable of iterate day by day printing the day in the format yyyy-MM-dd
But I'm getting the following error:
"Cannot invoke 'stride' with an argument list of type '(from: Date, to: Date, by: Int)'"
What have I tried?
My dates are conforming the strideable protocol
extension Date: Strideable {
public func distance(to other: Date) -> TimeInterval {
return other.timeIntervalSinceReferenceDate - self.timeIntervalSinceReferenceDate
}
public func advanced(by n: TimeInterval) -> Date {
return self + n
}
}
So I could use the stride Function
stride(from: <#T##Strideable#>, to: <#T##Strideable#>, by: <#T##Comparable & SignedNumeric#>)
On my ViewDidLoad in trying to run it
override func viewDidLoad() {
super.viewDidLoad()
let formatter = DateFormatter()
formatter.dateFormat = "yyyy/MM/dd"
let startDate = formatter.date(from: "2014/01/01")
let endDate = formatter.date(from: "2019/03/31")
let dayDurationInSeconds = 60*60*24
for date in stride(from: startDate!, to: endDate!, by: dayDurationInSeconds) {
print(date)
}
}
What do I expect to see on my console?
2014-01-01
2014-01-02
2014-01-03
.........
2019-03-30
2019-03-31