Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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,650 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!