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 Struct Initialization

S B
S B
4,497 Points

Why is the UI Image Initialization treated different from the title and description initializations?

How did Pasan know to create a constant for the small and large images? Why wouldn't the code which was used for title and description work for image as well?
I.e. largeIcon = playlistDictionary["largeIcon"] as String!

The thing that confuses me about all this is how did Pasan know to approach the image initialization like that? If i were to begin programming a similar app from scratch, I would never think of doing this. Any clarification on how to become more independent with the creation process from scratch (using this example) would be greatly appreciated.

1 Answer

Pasans datasource is a dictionary where images are represented by names. To actually get the image he has to use that name to retrieve the image from the apps resources. largeIcon = playlistDictionary["largeIcon"] as String! would work just fine, but then the icon would be a string and not an image. So instead he first gets the image name and then creates a UIImage using that name. Makes sense? In terms of how to become more independent, you can't beat trial and error. While programming is based on well defined syntax, you need to get your hands dirty to get experience. Your first apps will NOT be well structured, no matter how well you study - of course there are always exceptions to the rule :)

S B
S B
4,497 Points

Rasmus, you're awesome. Thank you so much!

You're welcome - any time :)