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
tighe C
Courses Plus Student 1,811 PointsNSData error Making a Network Call in the weather app
For the NSData class initializer I used the one in the teacher's notes. This gives me the data error that it unexpectedly found nil while unwrapping an optional. What can I do to fix this.
import UIKit
class ViewController: UIViewController {
private let apiKey = "The api Key I put in*"
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: "Coordinate of my location*, coordinate of my location*", relativeToURL: baseURL)
let weatherData = NSData(contentsOfURL: forecastURL!, options: nil, error: nil)
println(weatherData)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
*Not what I literally put in
5 Answers
Naomi Freeman
Treehouse Guest TeacherCould you please post your whole code from the ViewController?
What is after let baseURL = and let forecastURL =
What are these ^ set to?
Patrick Li
2,434 PointsThis is what happened to me too and I don't know what to do.
tighe C
Courses Plus Student 1,811 PointsFound it out nevermind
Naomi Freeman
Treehouse Guest TeacherGreat work :) What was the problem?
David Kong
3,710 PointsI'm getting this also - what was the issue?
Guy Barr
2,202 PointsWas having the same issue, my fix was removing any space from between the GPS co ordinates (especially if you copy and paste from Google as per the video)