In my app I am we are sending TimeStamp along with parameters for API calls to get data from. I could use any random string to pass with the values but I am using TimeStamp because it will be different everytime so that I will get fresh data everytime without cashing. Now our requirement is to update TimeStamp every hour so that everytime when I make an API call instead of showing fresh data everytime, data will be updated every hour.
My API looks like this:
let url = "https://myurl.api.getthisapidata?id=\(someID)&nocache=\(timeStamp)"
Now in the place of TimeStamp I want to send some random string like "\(arc4random())"
. But I want this random string to be changed only after an hour so that I go to some other view or closes the app and opens it before an hour this random string should remain same.
I hope you understand what I am trying to convey.
TimeStamp extenstion:
extension Date {
var ticks: UInt64 {
let timeStamp = UInt64((self.timeIntervalSince1970 + 62_135_596_800) * 10_000_000)
return timeStamp
}
}
Usage:
print(Date().ticks)