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

Execution was interrupted reason: EXC_BAD_INSTRUCTION

Getting error with these lines of code

private let apiKey = "APIKEYNUMBERS"

let baseUrl = NSURL(string: "https://api.forecast.io/forecast/\(apiKey)/")

let forcastUrl = NSURL(string: "32.995252, -94.965818", relativeToURL: baseUrl)

let weatherData = NSData.dataWithContentsOfURL (forcastUrl, options: nil, error: nil)

3 Answers

Hey,

had the same error and found it!

The error is that you have a space in the location string!

First I had:

let location = "48.277593, 12.160272"

and the app crashed - but without the space

let location = "48.277593,12.160272"

all worked just fine.

Hope this helped!

I figured it out, thank you for your help.

This is the issue I was having. Pasan said we could copy and past the location data from Google and just copy and pasting it ends up introducing a very hard to spot space in the final "forecastURL".

Try this line of code:

let dataObject = NSData(contentsOfURL: forcastUrl)

The error that I'm getting is on the forcatsUrl. I don't know why this is happening.

let forcastURL = NSURL(string: "00.000000, __ -00.000000", relativeToURL: baseURL)

REMOVE SPACE __ and replace to

let forcastURL = NSURL(string: "00.000000,-00.000000", relativeToURL: baseURL)