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!
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
Apoorv Pal4,130 Points
I am getting an error while executing my code
I wrote this -
let dataObject = NSData(contentsOfURL: location) let weatherDictionary: NSDictionary = NSJSONSerialization.dataWithJSONObject(dataObject, options:nil, error: nil) as NSDictionary
and getting error -
Type NSdata? does not conform to protocol 'AnyObject'
Blend88 Web Studios8,056 Points
I think you need to use NSJSONSerialization.JSONObjectWithData() and not NSJSONSerialization.dataWithJSONObject()
Stone Preston42,016 Points
returns an NSData optional.
however, dataWithJSONObject most likely expects a regular, non optional NSData object as its first argument
try force unwrapping the NSData object by placing a ! (bang) after the dataObject argument in the call to dataWithJSONObject
let dataObject = NSData(contentsOfURL: location) let weatherDictionary: NSDictionary = NSJSONSerialization.dataWithJSONObject(dataObject!, options:nil, error: nil) as NSDictionary