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 Simple Data Structures Modeling the Current Weather

Expected type after 'as'

Expected type after 'as'

I have problem when following the code in video: temperature = weatherDictionary["temperature"] as! Int

I already do same step by step just like the video but at mine an error show up.

The 'as!' notation was not introduced until Xcode 6.3. Lower Xcode versions do not understand 'as!' that is the cause of the compiler error you are getting. You will have to use simple 'as' if your Xcode version is a lower than Xcode 6.3.

1 Answer

I find it interesting that it was indicated that this has all been gone through before, but

temperature = weatherDictionary["temperature"] as! Int

does not work for me because of my version... and I have not encountered the as with a bang before. That particular thing has not been covered before and would be worthy of a versioning note, IMO.

Andre Kovac
Andre Kovac
5,588 Points

I second that! Before something like

temperature = weatherDictionary["temperature"] as Int!

was discussed. But, not as!.