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 Fetching JSON Data

Amrit Khokhar
Amrit Khokhar
592 Points

Stuck on a challenge

What is wrong with this code?

import Foundation let treehouseBaseURL = NSURL(string: "https://api.teamtreehouse.com/") let courseURL = NSURL(string: "/course/(courseID)", relativeToURL: treehouseBaseURL) let courseData = NSData.dataWithContensOfURL( courseURL , options: nil , error: nil) println(courseData)

1 Answer

Matt West
Matt West
14,545 Points

Hi Amrit,

There's a few things to watch out for here.

  • There's a small typo in NSData.dataWithContentsOfURL (missing a t in Conten*t*s)
  • Drop the / from the beginning of /course/(courseID). You already have a trailing forward-slash on https://api.teamtreehouse.com/ so it's not needed.
  • String interpolation requires a backslash followed by parentheses containing the variable. You're missing the forward-slash, so it should be: course/\(courseID).

Hope this helps :)