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


Swift Extra Credit.

Create an array of 10 songs where each song is a dictionary. The dictionary contains the following keys: title, artist and album.

How would you solve this? I am a bit confused.

4 Answers

Marie Mosley
Marie Mosley
14,248 Points

I did it a little differently. Here's the first two from my array:

let songs = [
["title": "Starman", "artist": "David Bowie", "album": "The Rise and Fall of Ziggy Stardust and the Spiders from Mars"],
["title": "Spellbound", "artist": "Siouxsie and the Banshees", "album":"Juju"]

Going a little further, I played around with this and found how to access things inside the dictionary. For example, writing this:


will get you:

{Some "Siouxsie and the Banshees"}

Nicklas Lind
Nicklas Lind
3,619 Points

Great answer, thank you :)

Srinivasan Senthil
Srinivasan Senthil
2,266 Points

Excellent. This answer gave multiple practices for Arrays and Dictionaries. Thanks so much

Stephen McMillan
.a{fill-rule:evenodd;}techdegree seal-36
Stephen McMillan
iOS Development with Swift Techdegree Graduate 33,994 Points
// Songs Dictionary
let firstSong = ["name" : "Rude", "artist" : "Magic", "album" : "Don't Kill the Magic"]
let secondSong  = ["name" : "Am I Wrong", "artist" : "Nico and Vinz", "album" : "The Magic Soup and the Bittersweet Faces"]

// Songs Array
var songsArray = [firstSong, secondSong]

Oh man why didn't I think of that, that makes perfect sense now. Thanks

Something related to this. Where do we put the answer to the extra credit ? When I click on that portion for extra credit, it seems to be grayed out.

Its just something you do on your own and see if it works. You don't submit it anywhere.

might of misunderstood the question but here's my answer ( only did 5) var songs: [String] = ["bat out of hell", "Knockin on Heaven's Door", "Number of the Beast", "Over the Rainbow", "Thriller" ]

var songDictionary = [songs[0]: "Meat Loaf, Bat Out Of Hell", songs[1]: "Guns and Roses, Use your Illusion 2", songs[2]: "Iron Maiden, Killers", songs[3]: "Eva Cassidy, Songbird", songs[4]: "Michael Jackson, Thriller"]