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

JSONP API Response in Swift

I just finished the Weather-App in the iOS swift course. Now I´d like to use the metric system for my App. I read that I need to return a API response in JSONP to the Forecast API. I also found the needed parameters but i haven´t found any possibility to "send" a response with parameters to the API.

Does somebody have a link to an explanation of how to respond to an API or can someone tell me which function i need to use?

Thanks for your help.

2 Answers

If I've read the Forecast API docs correctly, just tacking on ?units=si to the end of the request URL you make will change everything to metric.

I concur with Ryan's response. I just implemented a slightly more specific instance of ?units=si option for my Canadian location (i.e., ?units=ca) and it is working perfectly.

Here is the code I implemented if anyone is interested:

let baseURL = NSURL(string: "https://api.forecast.io/forecast/\(apiKey)/")

let forecastURL = NSURL(string: "57.381735,-128.150757?units=ca", relativeToURL: baseURL)