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
Rolando Cruz
2,995 PointsCast from 'NSData?' to unrelated type 'NSDictionary' always fails - yellow error
I get that error with this code:
if (error == nil) {
let dataObject = NSData(contentsOfURL: location)
let weatherDictionary: NSDictionary = NSJSONSerialization.dataWithJSONObject(dataObject!, options: nil, error: nil) as! NSDictionary
}
1 Answer
Marcos Griselli
3,188 PointsGet the data and then turn it into a dictionary using NSKeyedUnarchiver
let weatherData = NSJSONSerialization.dataWithJSONObject(dataObject!, options: nil, error: nil)
let weatherDictionary: NSDictionary = NSKeyedUnarchiver.unarchiveObjectWithData(weatherData!) as! NSDictionary
Rolando Cruz
2,995 PointsRolando Cruz
2,995 Pointsnow it gives me a breakpoint :/ in the video it didn't mention using NSKeyedUnarchiver