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 trialJoseph Kandi
2,640 PointsWhy are we not checking the value of the title since its been declared as an optional String
We are checking for the optional playlist stored property but we did also declare the title of the playlist to have an optional title, why are we not checking for a nil value in the title of the playlist?
3 Answers
Marie Nipper
22,638 PointsA few videos back he explains why he set it as an optional value. It would be good to check to see if it is an optional if it was data from the web that could return nil. However, it shouldn't return nil as the data is hard coded in the MusicLibrary struct. So that's my guess as to why he's not worried about checking for a nil value.
kjvswift93
13,515 PointsCould you maybe rephrase your question? I don't quite understand what you are asking.
Joseph Kandi
2,640 PointsOn the video "Passing the Playlist Object", Parsan creates an optional playlist stored property, and later on he checks for a nil value but does not also check for nil on the playlist title property, my question is , why is that? Why check only for the playlist property and also not for its title since its been declared as an optional string in the struct?
Rafael Schwemmer
6,109 PointsI think it is because we are already unwrapping the title in the init method of the Playlist struct:
title = playListDictionary["title"] as! String!
So when we create an instance of the Playlist struct, the title is automatically unwrapped.