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

Seth Dobrin
Seth Dobrin
1,459 Points

EXC_BAD_INSTRUCTION

I get the above error when running my code...

let baseURL = NSURL(string:"https://api.forecast.io/forecast/\(apiKey)/")
let forecastURL = NSURL(string: "38.607550, -90.622682", relativeToURL:baseURL)
let weatherData = NSData(
    contentsOfURL: forecastURL!,
    options: nil,
    error: nil)

and I can't seem to figure out what the cause is. my monthly allotment in forecast.io does not get decrement either

1 Answer

Chris Shaw
Chris Shaw
26,676 Points

Hi Seth,

This error has caught quite a number of students off guard and it's quite hard to spot if you're new to iOS development, the error is being caused by the space in the coordinates value you have; after the comma which NSURL objects don't like, simply remove that space and the error will go away.

let forecastURL = NSURL(string: "38.607550,-90.622682", relativeToURL: baseURL)

Happy coding!