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 Interacting with Data From the Web Constructing a URL

Marina Alenskaja
Marina Alenskaja
9,320 Points

Constructing URL

Hey, can someone please help me understand what's wrong here?

In the video, the construction of the URL looks like this:

let baseURL = NSURL(String: https://api.forecast.io/forecast/\(forecastAPIKey)”)

When i wrote out the following code however...:

let treehouseBaseURL = NSURL(String: "https://api.teamtreehouse.com/\(treehouseCourseID)/")

...It said "expected "fileURLWithPath" instead of String. So I tried that:

import Foundation

let treehouseCourseID = 25

// Add your code below
let treehouseBaseURL = NSURL(fileURLWithPath: "https://api.teamtreehouse.com/\(treehouseCourseID)/")

Didn't work either.. This is the error I'm getting: "Make sure you instantiate treehouseBaseURL to the correct URL."

What am I missing? And why does the video succed in using String, when the challenge doesn't accept it?

1 Answer

Jhoan Arango
Jhoan Arango
14,575 Points

Hello Marina :

Well you are on the right path, but the first part of the challenge does not require you to use the threehouseCourseID just yet. Remember the BASE url is one that will NOT change, hence the name Base. It's like https://www.google.com/maps/place/miami, the last part of this url will change depending on the city that you search that map on. So it could be www.google.com/maps/place/newyork, but notice how the www.google.com/maps/place does not change.

let treehouseCourseID = 25

// Creating an instance of the URL Base.
let treehouseBaseURL = NSURL(string: "https://api.teamtreehouse.com/")

I won't spoil the second part of the challenge, I am sure you can figure that one out :)

Good luck.

Marina Alenskaja
Marina Alenskaja
9,320 Points

Thanks! That's what I wrote out the first time but string with a capital - maybe that was the problem...

Jhoan Arango
Jhoan Arango
14,575 Points

No problem.. :) It happens.