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 trialFred Sites
11,151 Points'NSNumber' Is not a subtype of 'NSData' error on Xcode6.1...
I've gone through all other questions and made necessary changes for the project to work in 6.1 but can't seem to figure out this error. I keep getting 'NS number is not a subtype of 'NSData'
let weatherDictionary: NSDictionary = NSJSONSerialization.JSONObjectWithData(!dataObject, options: nil, error: nil) as NSDictionary
2 Answers
Stone Preston
42,016 Pointsyou have your ! at the front of the data object, put it behind. when using an explicitly unwrapped optional you put the ! after the variable name:
let weatherDictionary: NSDictionary = NSJSONSerialization.JSONObjectWithData(dataObject!, options: nil, error: nil) as NSDictionary
what you currently are using is a boolean not operator which evaluates to either true or false.
Fred Sites
11,151 PointsThanks Stone!