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

help 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)

Are you getting errors?

yeah its saying, Bummer! You need to call the dataWithContentsOfURL method on NSData.?

6 Answers

Okay 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 :)

Try changing dataWithContentsOfUrl to contentsOfURL

import 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.

Did you change dataWithContentsOfUrl to contentsOfURL in the second code that Chirs used? I tried that and it came out right for me.

You 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)

You aren't passing anythin go the method dataWithContentsOfURL

you have set options to nil and error to nil. but data you have left blank.

I'm getting the same error.

import 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?