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 Playlist Browser with Swift Building the Music Library and Playlist Models Creating UIImageView instances

Chris Shei
Chris Shei
1,827 Points

Help understanding the answer to playlist code challenge 6602 (I think?)

Why do i need to unwrap the value obtained from the dictionary? I don't see an optional.

Why do I need the 'named' part?

Where can I read / learn more about how 'as' is used?

Answer: let profileImageName = friends["profilePicture"] as String!
let profilePicture : UIImage = UIImage(named: profileImageName)

1 Answer

Richard Lu
Richard Lu
20,185 Points

Hi Chris,

To learn more about how 'as' is used, you can take a look at Apples documentation in regards to type casting. Here's a link to the referenced document.

Link: http://tinyurl.com/ojr3t39

What you're looking for specifically is under the downcasting section. I hope I've helped. Happy Coding! :)

Chris Shei
Chris Shei
1,827 Points

Very helpful. Thanks