And the above was based on this playground I created first which does work.
struct Weather {
let days: [Double]
let forcasts: [Forcast]
}
struct Forcast {
let info: [String]
}
var weatherDetails = [Weather]()
weatherDetails.append(Weather(days: [1600362000.0], forcasts: [Forcast(info: ["Clouds"])]))
weatherDetails.append(Weather(days: [1600448400.0], forcasts: [Forcast(info: ["Rainy"])]))
weatherDetails.append(Weather(days: [1600534800.0], forcasts: [Forcast(info: ["Clear"])]))
weatherDetails.append(Weather(days: [1600621200.0], forcasts: [Forcast(info: ["Smoke"])]))
weatherDetails.append(Weather(days: [1600707600.0], forcasts: [Forcast(info: ["Clear"])]))
weatherDetails.append(Weather(days: [1600794000.0], forcasts: [Forcast(info: ["Clear"])]))
weatherDetails.append(Weather(days: [1600880400.0], forcasts: [Forcast(info: ["Smoke"])]))
let actualDays = ["Wednesday", "Thursday", "Friday", "Saturday", "Sunday", "Monday", "Tuesday"]
var xDays = [String]()
var xForcast = [String]()
var xDictionary: [String : String] = [:]
func convertDate(timezone: Int, passedDate: Double) {
let unixTimestamp = passedDate
let date = Date(timeIntervalSince1970: unixTimestamp)
let dateFormatter = DateFormatter()
dateFormatter.timeZone = TimeZone(abbreviation: "UTC")
dateFormatter.dateFormat = "EEEE"
dateFormatter.timeZone = TimeZone(secondsFromGMT: timezone)
let strDate = dateFormatter.string(from: date)
xDays.append(strDate)
}
weatherDetails.forEach { (item) in
convertDate(timezone: -18000, passedDate: item.days[0])
}
weatherDetails.forEach { (item) in
item.forcasts.forEach { (forcast) in
xForcast.append(forcast.info[0])
}
}
for (index, element) in xDays.enumerated() {
xDictionary[element] = xForcast[index]
}
func getWeatherInfo(day: String) {
let filtered = xDictionary.filter { $0.key == day }
let theValue = filtered.values
print("The Value \(day): \(theValue.first ?? "")")
}
xDictionary.forEach { print($0) }
getWeatherInfo(day: "Friday")
actualDays.forEach { (item) in
getWeatherInfo(day: item)
}
(key: "Saturday", value: "Clear")
(key: "Wednesday", value: "Smoke")
(key: "Thursday", value: "Clouds")
(key: "Friday", value: "Rainy")
(key: "Monday", value: "Clear")
(key: "Tuesday", value: "Clear")
(key: "Sunday", value: "Smoke")
The Value Friday: Rainy
The Value Wednesday: Smoke
The Value Thursday: Clouds
The Value Friday: Rainy
The Value Saturday: Clear
The Value Sunday: Smoke
The Value Monday: Clear
The Value Tuesday: Clear