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

Philip Ondrejack
Philip Ondrejack
4,287 Points

Why do we have to create a helper method?

Why can't we do this in the init method?

backgroundColor = playlistDictionary["backgroundColor"] as UIColor!

2 Answers

If I remember correctly I think he is having you create a method because the background color will change depending on which playlist the user selects.

playlistDictionary["backgroundColor"] does not return a color, but rather a dictionary with rgb-values. So you need to instantiate a UIColor from those values. That said, there is absolutely no reason for putting this in a "helper method", since (for now) it is only being called once to set the background in the initialiser ... well, except for learning to separate your code into reusable parts :)