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

Allan Noguera
PLUS
Allan Noguera
Courses Plus Student 2,421 Points

What is the correct answer for the challenge, fetching json data?

i have tried to pass this challenge and I know my answer is correct. But is not letting me pass. What is the correct answer for this challenge.

Thanks

students_code.swift
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)

1 Answer

Greg Kaleka
Greg Kaleka
39,021 Points

Hi Allan,

Your method call is not quite right. Here's the correct syntax:

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

Note: I haven't seen the video recently, but Swift is a young, changing language, and it's entirely possible the video shows a different way to call this method which has since been changed. When in doubt, check Apple's documentation! Being able to find and understand the entry in the docs you need is a great skill to master.

Allan Noguera
Allan Noguera
Courses Plus Student 2,421 Points

Thanks, yes I am quiet sure it is changing, but I thought that the answer was based on the video content. I appreciate your help!

Chris Shaw
Chris Shaw
26,676 Points

For clarity this change has being mentioned in the teachers notes and outlines the change.