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
Chirs Davies
6,379 Pointshelp please
Let's assume that the courseURL we created earlier returns some JSON data from Treehouse API. Create a data object to capture this information, and store it in a constant named courseData. Hint: Use the NSData class. You can set options and error to nil.
import Foundation
let treehouseBaseURL = NSURL(string: "https://api.teamtreehouse.com/")
let courseURL = NSURL(string: "/course/\(courseID)", relativeToURL: treehouseBaseURL)
let courseData = NSData(dataWithContentsOfURL: options: nil, error: nil)
Chirs Davies
6,379 Pointsyeah its saying, Bummer! You need to call the dataWithContentsOfURL method on NSData.?
6 Answers
Glen Burnett
Courses Plus Student 27,349 PointsOkay this sucker of a code challenge has been bothering me for days! I reported what I thought to be some potential bug issues but I have found the solution to this challenge. I am going to put everyone out of their misery by providing the solution....
let treehouseBaseURL = NSURL(string: "https://api.teamtreehouse.com/")
let courseURL = NSURL(string: "/course/\(courseID)", relativeToURL: treehouseBaseURL)
let courseData = NSData(contentsOfURL: courseURL)
This worked for me. A couple of times it sort of timed out and gave me that sorry there was a problem communicating and I had to re-try the challenge but a third time it accepted it. THIS is the correct solution guys.
Hope this puts many poor souls out of their misery :)
Bretney Scott
20,319 PointsTry changing dataWithContentsOfUrl to contentsOfURL
Uday Singh
2,999 Pointsimport Foundation
let treehouseBaseURL = NSURL(string: "https://api.teamtreehouse.com/")
let courseURL = NSURL(string: "/course/\(courseID)", relativeToURL: treehouseBaseURL)
let courseData = NSData.contentsOfURL(url:courseURL, options:nil, error:nil)
^ Still results in error.
Bretney Scott
20,319 PointsDid you change dataWithContentsOfUrl to contentsOfURL in the second code that Chirs used? I tried that and it came out right for me.
Peter Simpson
Courses Plus Student 15,526 PointsYou need to do it the old redundant way, as it is shown in the video or else it wont work in the simulator. try this code ---
let courseData = NSData.dataWithContentsOfURL(url:courseURL, options:nil, error:nil)
Cody Coats
7,469 PointsYou aren't passing anythin go the method dataWithContentsOfURL
you have set options to nil and error to nil. but data you have left blank.
Uday Singh
2,999 PointsI'm getting the same error.
Chirs Davies
6,379 Pointsimport Foundation
let treehouseBaseURL = NSURL(string: "https://api.teamtreehouse.com/")
let courseURL = NSURL(string: "/course/\(courseID)", relativeToURL: treehouseBaseURL)
let courseData = NSData(dataWithContentsOfURL: courseURL, options: nil, error: nil)
I passed courseURL but im still getting an error?
Cody Coats
7,469 PointsCody Coats
7,469 PointsAre you getting errors?