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 Making a Network Call

Hi i tried to code exactly as you say in the video but it gives an error when running it. NSURL? not unwrapped??

Hi i tried to code as you say in the video but it gives an error when running it. NSURL? not unwrapped?? also the download files give the same error

Patrick Gerrits
Patrick Gerrits
14,614 Points

Please give us some more information about what code you have right now?

class ViewController: UIViewController {

//Replace the string below with your API Key.
private let apiKey = "4de5319c1c8991a1ff2985013795b0b3"

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.

    let baseURL = NSURL(string: "https://api.forecast.io/forecast/\(apiKey)/")
    let forecastURL = NSURL(string: "37.8267,-122.423", relativeToURL: baseURL)

    let weatherData = NSData.dataWithContentsOfURL(forecastURL, options: nil, error: nil)
    println(weatherData)
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

}

2 Answers

I just posted some code that compiles correctly under the Questions section of this video. Given that Swift has changed quite a bit, the code in the video will not work until it gets updated by the Treehouse team. My code compiles and at least will let you move forward with the course until they get a chance to rework the material. Hope it helps!

I walk around of the problem by omitting the space between latitudes.