Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

iOS

Laurence Bowe
Laurence Bowe
6,221 Points

Swift weather app Fahrenheit to Celsius?

Hey, Was just wondering whether anyone had solved this so us Aussies can understand it better.

Should probably change the hey to G,Day mate! :) (:

THANKS HEAPS IN ADVANCE!!!

2 Answers

Brad Van Skyhawk
Brad Van Skyhawk
28,489 Points

C is Celsius and F is Fahrenheit. You would take the temperature from forecast.io (which is in Fahrenheit) and then substitute into the formula. Something like this:

You make temperature optional with ? in the declaration

add this in the init function:

    let fahrenheit = currentWeather["temperature"] as Int
    temperature = convertToCelsius(fahrenheit)

add this function to convert it:

func convertToCelsius(fahrenheit: Int) -> Int {
    return Int(5.0 / 9.0 * (Double(fahrenheit) - 32.0))
}
Brad Van Skyhawk
Brad Van Skyhawk
28,489 Points

It looks like forecast.io only return the temperature in Fahrenheit. You can convert in the Current struct with this formula:

C = 5/9 * (F-32)

Laurence Bowe
Laurence Bowe
6,221 Points

WOW, THANKS SO MUCH FOR HELPING OUT AND GIVING UP SOME OF YOUR TIME!!! MEANS AND HELPS ALOT!!! Though how do you implement this in the code, what is C and F? THANKS AGAIN