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 (Retired) Pulling Data From the Web Creating a URL

Johannes Böhm
Johannes Böhm
5,957 Points

cant get it working

Here is my Code: import Foundation

let courseID = 25

let treehouseBaseURL = NSURL(string: "https://api.teamtreehouse.com/")

let courseURL = NSURL(string:"courseID", relativeToURL: treehouseBaseURL)

I am aware the in the URL there is the "/course/" missing, but I dont know how to add this, or where. Also I think I need to convert the courseID = 25 into a string and I am not sure if a "25" will do the work.

Any hints? Would be great!

1 Answer

Stone Preston
Stone Preston
42,016 Points

this challenge is pretty tough since it does not really give you much direction.

you need to use string interpolation to interpolate the course ID onto the end of the string.

since the full url used to access a course looks something like "https://api.teamtreehouse.com/course/COURSE_ID", you can see that /course/COURSE_ID is the part of the url thats going to be relative to the base URL, which is "https://api.teamtreehouse.com/".

so interpolate the value of courseID onto the end of the string "course/" and use that as the string parameter.

import Foundation

let courseID = 25
let treehouseBaseURL = NSURL(string:"https://api.teamtreehouse.com/");
let courseURL = NSURL(string: "course/\(courseID)", relativeToURL: treehouseBaseURL);