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 Build a Weather App with Swift Managing Complexity Grand Central Dispatch

Dennis Henley
Dennis Henley
3,421 Points

Downloaded code fails on URL

I downloaded the project code for the building a weather app (my version failed on the URL call).

The downloaded version also fails on the URL call. Specifically, when I use the following code:

if let forecastURL = NSURL(string: "(lat),(lon)", relativeToURL: forecastBaseURL) { let networkOperation = NetworkOperation(url: forecastURL)

my forecastURL is returned as : 37.8267,-122.423 -- https://api.forecast.io/forecast/myactualAPIKey/

It appears to be putting the string in front of relativeToURL.

Again, let me stress that this was downloaded from the course. The only change I made was to put in my APIKey and to hit RUN. It compiles but does not correctly assemble the URL.

Any ideas?

Thanks.

Dennis Henley
Dennis Henley
3,421 Points

Well, here's what I discovered. I ran the code from my home computer and there was no failure. I connected to the site and retrieved the temperature, humidity, etc.

It looks like the network at work does not allow an iOS simulator to access the website even though I can access it via a browser.

It's always something…

I think it could also cause wrong string interpolation

YOU'v got "(lat),(lon)" but it should be "(lat),(lon)"

still doesn't work here, it give me a 400 http code and the forecastBaseURL like this: 37.8267,-122.423 -- https://api.forecast.io/forecast/myactualAPIKey/

Aubrey Taylor
Aubrey Taylor
2,991 Points

Mauro

I had the same issue as you. Turns out I was missing a slash at the end of my forecastBaseURL string. My code now works as it's written in the video.

2 Answers

Roberta Voulon
Roberta Voulon
5,792 Points

There's nothing you're doing wrong, it's just a difference in how the Playground works between different versions of Xcode. You'll need to manually assemble the url by pasting the coordinates after the rest of it, like so:

https://api.forecast.io/forecast/myactualAPIKey/37.8267,-122.423

Jacque Porter
Jacque Porter
5,677 Points

For some the answer may simply be a typo in the URL at the top of ForecastService.swift. I was getting this error because I had misspelt "forecast" as "forcast"