I'm grabbing data from an api, and one of the values I'm getting is for day of the week, the data returned from api looks like this:
"time": 1550376000
I created this function to get the date:
func getDate(value: Int) -> String {
let date = Calendar.current.date(byAdding: .day, value: value, to: Date())
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "E"
return dateFormatter.string(from: date!)
}
but was told there is a much safer way to get it instead of assuming we get consecutive days starting with today. Does anyone know how to build a date out of the time field (it is seconds since midnight 1970) and then use Calendar and DateComponent to figure out the day?