For starters, I would create an object
class Weather { var maxTemp: Double! var minTemp: Double! var sunnyDays: Int! init (_ maxTemp: Double, minTemp: Double, sunnyDays: Int) { self.maxTemp = maxTemp self.minTemp = minTemp self.sunnyDays = sunnyDays } }
Next, I would create a dictionary in which I would store all the data.
var data: [String: Any] = [:]
the key to the data would be in the format yyyy-m
would write data like this
data["2014-4"] = Weather(23.4, 3.1, 12)
And then I would list all the years, within the years of the month, and refer to the data for the year + month, since they are known to us.
If you wish, you can store months within years, and within months already given:
var data: [String: [Weather]] = [:] data:["2014"].append[Weather(2.4, -13.1, 1)] //January data["2014"].append[Weather(5.4, -2.1, 3)] //February data["2014"].append[Weather(10.4, 3.1, 6)] //March data["2014"].append[Weather(15.4, 3.1, 12)] //April data["2014"].append[Weather(23.4, 3.1, 12)] //May
The list of years can be made manually
var yearsList: [Int] = [] for y in 2010...2017 { yearsList.append(y) }
Months within the same year, it is always a range of 0 ... 11. In general, at the entrance you will probably have JSON with data in which there will be both a year and a month, you just need to write all this into the structure prepared above.