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
Tyler Amend
2,236 PointsHow to store dictionaries in an array?
I'm working on the song array challenge in the iOS track and am having trouble getting it to work proper. I'm getting a notification that says string:string is not convertible to int, which I understand what it means, but unsure how to fix it since I can't designate the array as a string.
import UIKit
let songOne = ["Title": "Summer Highland Falls", "Artist": "Billy Joel", "Album": "Turnstiles"] let songTwo = ["Title": "Angry Young Man", "Artist": "Billy Joel", "Album": "Turnstiles"] let songThree = ["Title": "Zanzibar", "Artist": "Billy Joel", "Album": "52nd Street"] let songFour = ["Title": "Vienna", "Artist": "Billy Joel", "Album": "The Stranger"] let songFive = ["Title": "All for Leyna", "Artist": "Billy Joel", "Album": "Glass Houses"] let songSix = ["Title": "I Don't Want to Be Alone", "Artist": "Billy Joel", "Album": "Glass Houses"] let songSeven = ["Title": "Sleeping with the Televsion On", "Artist": "Billy Joel", "Album": "Glass Houses"] let songEight = ["Title": "Piano Man", "Artist": "Billy Joel", "Album": "The Essential Billy Joel"] let songNine = ["Title": "An Innocent Man", "Artist": "Billy Joel", "Album": "The Essential Billy Joel"] let songTen = ["Title": "A Matter Of Trust", "Artist": "Billy Joel", "Album": "The Essential Billy Joel"]
var songArray = [songOne, songTwo, songThree, songFour, songFive, songSix, songSeven, songEight, songNine, songTen]
songArray [songOne]
Tyler Amend
2,236 PointsTyler Amend
2,236 PointsI figured out what the problem was. Is there a cleaner, perhaps more elegant solution to the problem than what I have come up with? See code below.
''' import UIKit
let songOne = ["Title": "Summer Highland Falls", "Artist": "Billy Joel", "Album": "Turnstiles"] let songTwo = ["Title": "Angry Young Man", "Artist": "Billy Joel", "Album": "Turnstiles"] let songThree = ["Title": "Zanzibar", "Artist": "Billy Joel", "Album": "52nd Street"] let songFour = ["Title": "Vienna", "Artist": "Billy Joel", "Album": "The Stranger"] let songFive = ["Title": "All for Leyna", "Artist": "Billy Joel", "Album": "Glass Houses"] let songSix = ["Title": "I Don't Want to Be Alone", "Artist": "Billy Joel", "Album": "Glass Houses"] let songSeven = ["Title": "Sleeping with the Televsion On", "Artist": "Billy Joel", "Album": "Glass Houses"] let songEight = ["Title": "Piano Man", "Artist": "Billy Joel", "Album": "The Essential Billy Joel"] let songNine = ["Title": "An Innocent Man", "Artist": "Billy Joel", "Album": "The Essential Billy Joel"] let songTen = ["Title": "A Matter Of Trust", "Artist": "Billy Joel", "Album": "The Essential Billy Joel"]
var songArray = ["Summer Highland Falls": songOne, "Angry Young Man": songTwo, "Zanzibar": songThree, "Vienna": songFour, "All for Leyna": songFive, "I Don't Want to Be Alone": songSix, "Sleeping with the Television On": songSeven, "Piano Man": songEight, "An Innocent Man": songNine, "A Matter Of Trust": songTen]
songArray ["Summer Highland Falls"]