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
Frank Ogwaro
Courses Plus Student 7,941 PointsNSURL string? Pulling Data from the Web
To access information about a course we can use a URL like: https:// api.teamtreehouse.com/course/COURSE_ID. Given the variable courseID, create an absolute URL, named courseURL, to retrieve information about a user's progress on a certain course. It should have a path that's relative to the treehouseBaseURL.
I'm not sure what I'm suppose to pass in for the NSURL string. My thought was to pass in the courseID using string interpalation but it didn't work. Help would be much appreciated.
import Foundation
let courseID = 25
let treehouseBaseURL = NSURL(string: "https://api.teamtreehouse.com/course\(courseID)/")
let courseURL = NSURL(string: "", relativeToURL: treehouseBaseURL)
7 Answers
hui yi yeh
7,199 Pointslet courseID = 25
let treehouseBaseURL = NSURL(string: "https://api.teamtreehouse.com/")
let courseURL = NSURL(string: "course/\(courseID)", relativeToURL: treehouseBaseURL)
MUZ140563 Brighton Madire
4,365 Pointslet courseID = 25 let treehouseBaseURL = NSURL(string: "https://api.teamtreehouse.com/") let courseURL = NSURL(string: "course/(treehouseCourseID)", relativeToURL: treehouseBaseURL)
Frank Ogwaro
Courses Plus Student 7,941 PointsI tried that but it tells me that I need to convert the courseID variable to a string.
Samuel Behrens
4,576 PointsCan you just put qutoations around the 25:
let courseID = "25"
Frank Ogwaro
Courses Plus Student 7,941 PointsNo it wants me to pass a value in for the NSURL string.
Samuel Behrens
4,576 PointsI just entered this in exactly and it said it was right:
import Foundation
let courseID = 25
let treehouseBaseURL = NSURL(string: "https://api.teamtreehouse.com/")
let courseURL = NSURL(string: "course/(courseID)/", relativeToURL: treehouseBaseURL)
Frank Ogwaro
Courses Plus Student 7,941 PointsThanks hui yi yeh! After many tries your solution worked. :)
Samuel Behrens
4,576 PointsTry this:
import Foundation
let courseID = 25
let treehouseBaseURL = NSURL(string: "https://api.teamtreehouse.com/")
let courseURL = NSURL(string: "course(courseID)/", relativeToURL: treehouseBaseURL)
You needed to put the "course(courseID)/" in the courseURL because it is what you are adding to the base URL