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 trialChristian De Leon
11,304 PointsSwift 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
14,248 PointsI 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:
songs[1]["artist"]
will get you:
{Some "Siouxsie and the Banshees"}
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]
Christian De Leon
11,304 PointsOh man why didn't I think of that, that makes perfect sense now. Thanks
frederickparas
553 PointsSomething 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.
Christian De Leon
11,304 PointsIts just something you do on your own and see if it works. You don't submit it anywhere.
Sally Firby
5,263 Pointsmight 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"]
songDictionary[songs[2]]
Nicklas Lind
3,619 PointsNicklas Lind
3,619 PointsGreat answer, thank you :)
Srinivasan Senthil
2,266 PointsSrinivasan Senthil
2,266 PointsExcellent. This answer gave multiple practices for Arrays and Dictionaries. Thanks so much