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 trialJose Castro
1,953 Pointschallenge 2
I'm trying to understand treehouseBaseURL
import Foundation
let courseID = 25
let treehouseBaseURL = NSURL(string: "https://api.teamtreehouse.com/course/")
let courseURL = NSURL(string: \(courseID), relativeToUrl: treehouseBaseURL)
1 Answer
Stone Preston
42,016 Pointsyou are on the right track. the base URL is https://api.teamtreehouse.com/
to obtain info on a course, you use a URL that looks like this: https://api.teamtreehouse.com/course/someCourseID
where some courseID is an actual courseID
so the base URL is https://api.teamtreehouse.com/
and the full URL needs to look like https://api.teamtreehouse.com/course/someCourseID
. we can construct the full course URL using the NSURL(string: relativeToURL:)
method.
we have a course ID variable with a value of 25. we can interpolate that onto the end of the string "course/" to make the second half of the url. we can pass the baseURL in as the relativeToURL argument to build the complete URL that looks like https://api.teamtreehouse.com/course/25
import Foundation
let courseID = 25
let treehouseBaseURL = NSURL(string: "https://api.teamtreehouse.com/")
let courseURL = NSURL(string: "course/\(courseID)", relativeToURL: treehouseBaseURL)