Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

Deysha Rivera
Deysha Rivera
5,088 Points

Need Help Adding Weekly Data To Stormy Weather App in Swift

I am trying to add a table to the Stormy weather app to display weekly data. I created a new swift file to display the daily data from DarkSky API, but I am having trouble figuring out where to put the date formatter and how to request the date from DarkSky. I JUST want to have a label that displays the day of the week. This is what I have so far (I think I'm way off).

I have no idea where to put these lines of code:

    let time = Date(timeIntervalSince1970: 1453363200) // -> "Jan 21, 2016, 8:00 AM"
    let formatter = DateFormatter()
    formatter.dateFormat = "EEEE"

    let day = formatter.string(from: time)

This is modeled after the CurrentWeather model provided by Pasan in the tutorial.

struct WeeklyWeather: Codable {
    let temperatureHigh: Double
    let temperatureLow: Double
    let time: Int
    let day: String
    let icon: String
}

I also have in another swift file called DailyWeatherViewModel to display this weekly data:

struct WeeklyWeatherViewModel {
    let temperatureHigh: String
    let temperatureLow: String
    let time: String
    let icon: UIImage

    init(model: WeeklyWeather) {
        let roundedTemperatureHigh = Int(model.temperatureHigh)
        self.temperatureHigh = "\(roundedTemperatureHigh)ΒΊ"

        let roundedTemperatureLow = Int(model.temperatureLow)
        self.temperatureLow = "\(roundedTemperatureLow)ΒΊ"

        self.icon = model.imageIcon

        // add time/date initializer

    }
}
Caleb Kleveter
Caleb Kleveter
Treehouse Moderator 37,862 Points

I'll take a look at this when I get a chance. In the mean time, feel free to snoop around my own variation of Stormy that I built: https://github.com/calebkleveter/Meteorologist