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
Why a separate struct to access the information from MusicLibrary? We could just pull them from directly from M.Library?
The init methods in the Playlist struct look complicating. Why exactly do we need them? Couldn't we just pull the information from MusicLibrary directly?
In addition, why did we initialize everything in Playlist struct with an init method? Don't we initialize them previously by:
var title: String?
var description: String?
var icon: UIImage?
var largeIcon: UIImage?
var artists: [String] = 
var backgroundColor: UIColor = UIColor.clearColor()
We could, but then we would have to pass all the music library with all of its playlists between controllers. Since in the example, there were 6-7 playlists that may not seem like a problem but with real data it would be. Another reason would be, most of the time, the data won't be hard coded in the app. We will pull it from a database, or from a json file so you'd be designing just the playlist struct to handle the data in your app.
Lastly, the code you are mentioning is just the declaration of the stored properties with only two of them being given initial values. The actual values of the struct are initialized within the init method.