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) Concurrency Using Our JSON Data

David Petrin
David Petrin
3,384 Points

Downcasting in Xcode V6.3

I just updated to Xcode 6.3 and my code now shows an error at: let weatherDictionary: NSDictionary = NSJSONSerialization.JSONObjectWithData(dataObject!, options: nil, error: nil) as NSDictionary

I believe it suggests revising the line of code to: let weatherDictionary: NSDictionary = NSJSONSerialization.JSONObjectWithData(dataObject!, options: nil, error: nil) as! NSDictionary

Is this correct?

3 Answers

Joel Lopez
Joel Lopez
3,191 Points

Iam getting the same in but on the previous app (Playlist, algorhythm): description = playlistDictionary["description"] as String!

it wants to replace the as to as! to force downcast description = playlistDictionary["description"] as! String!

Jeanne Merle
Jeanne Merle
3,390 Points

Good Point David ! I had no idea what was the new method.

Michael Metzger
Michael Metzger
4,529 Points

HI Guys. I have Xcode 6.3 too. I found that you also have to unwrap the contents of dataObject.

            <p>let dataObject = NSData(contentsOfURL: location!)
            let weatherDicitonary: NSDictionary = NSJSONSerialization.JSONObjectWithData(dataObject!, options: nil, error: nil) as! NSDictionary</p>
            ```