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

help with the code challenge please

okay so my code for the second part of the challenge goes like this it is not accepted by the system , what am i missing ? help would be appreciated

1st part of the challenge ( got accepted)

import Foundation

let treehouseCourseID = 25

// Add your code below

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

let treehouseBaseURL = NSURL(string: "" , relativeToURL: baseURL)

2nd part (causing the error)

let courseURL = NSURL(string: "course/COURSE_ID/\(treehouseCourseID)" , relativeToURL: treehouseBaseURL)

2 Answers

Tobias Helmrich
Tobias Helmrich
31,603 Points

Hey there,

you almost got it right but there are two tiny problems in your code: Firstly the COURSE_ID is not part of the URL but it's like a placeholder for the actual ID of the course that is stored in treehouseCourseID . The other problem is that you shouldn't make treehouseBaseURL a relative URL but right now it's relative to baseURL . treehouseBaseURL however is the base URL.

So you can write it like this and it should work:

import Foundation

let treehouseCourseID = 25

// Add your code below

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

let courseURL = NSURL(string: "course/\(treehouseCourseID)", relativeToURL: treehouseBaseURL)

I hope that makes sense and helps, if you have further questions feel free to ask. Good luck! :)

Oh, ha, I was just looking for someone to help on the forums that didn't have an answer. I thought it was one of those things a fresh set of eyes can help with, since the one above it has the parenthesis outside. I apologize if I added to the confusion!

it did , helped me a lot , honeslty i took into consideration that "COURSE_ID" might be part of the url and i tried different forms but it wouldnt have worked since my first part of the challenge accepted my "baseURL" constant approach and i wouldnt have tried to mess with it.

thanks

Tobias Helmrich
Tobias Helmrich
31,603 Points

Hey Ericka,

you don't have to apologize! It's all about participating and you tried to help, that's great! :) I didn't mean what I said in a negative way, I just wanted to make it clear for Catalin that this part was actually perfectly fine!

You've most likely already caught this, but your closing quotation mark is outside the parenthesis.

NSURL(string: "course/COURSE_ID/(treehouseCourseID)"

Tobias Helmrich
Tobias Helmrich
31,603 Points

Hey there,

that part of the code is actually correct because the closing parenthesis you're referring to is part of the interpolated treehouseCourseID constant.

Don't worry about it Ericka , i kinda knew i wasnt wrong there , no confusion created , i appreciate makin time to try helping.