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

Connor Yee
Connor Yee
1,274 Points

NSData is nil

I cannot figure out why my NSData object is nil. Here is code:

    private let apiKey = "f80dccf0d7e91b5d57b748ecbfb5186c"


    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 forecast = NSURL(string: "/42.550949,-83.306352", relativeToURL: baseUrl)
        let forecastData = NSData(contentsOfURL: forecast!, options: nil, error: nil)
        println(forecastData)
    }

1 Answer

On your playground, copy thee second URL on your browser. It should load up the datas. I had the same problem and it worked