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 trialAmit Kalra
3,078 PointsAbsolute URL
This challenge is telling me to create an absolute URL, which I think I'm doing, I checked in Xcode, it seems to work fine. Why is the challenge marking this as wrong?
import Foundation
var treehouseCourseID = 25
// Add your code below
let treehouseBaseURL = NSURL(string: "https://api.teamtreehouse.com/")
let courseURL = NSURL(string: "/course/\(treehouseCourseID)", relativeToURL: treehouseBaseURL)
2 Answers
Greg Kaleka
39,021 PointsHi Amit,
I made EXACTLY this mistake on a PHP project I've been working on, so I feel your pain.
Your base URL ends with a forward slash, and the string you're adding to it starts with a forward slash, so you end up with:
https://api.teamtreehouse.com//course/...
The double slash is the problem. Just drop it from your courseURL constant.
import Foundation
var treehouseCourseID = 25
// Add your code below
let treehouseBaseURL = NSURL(string: "https://api.teamtreehouse.com/")
let courseURL = NSURL(string: "course/\(treehouseCourseID)", relativeToURL: treehouseBaseURL)
Cheers,
-Greg
Amit Kalra
3,078 PointsHaha, thank you! Turns out I had that written in Xcode but couldn't notice this difference in the challenge.
Chokdee Srisuk
19,384 PointsYou are using the wrong address in a constant of courseURL which is relative to baseURL. It's just a little error of a parenthesis appears in the courseURL. Check this out.
let courseURL = NSURL(string: "course/(treehouseCourseID)", relativeToURL: treehouseBaseURL)
Hopefully it can help you out.
Chokdee Srisuk
19,384 PointsChokdee Srisuk
19,384 PointsYou are using the wrong address in a constant of courseURL which is relative to baseURL. It's just a little error of a parenthesis appears in the courseURL. Check this out.
let courseURL = NSURL(string: "course/(treehouseCourseID)", relativeToURL: treehouseBaseURL)
Hopefully it can help you out.