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 trialRani Shayto
769 PointsDictionary function extracredit
Hello,
I am attempting to do the dictionary function extra-credit, and the longer I try the more I forget the basics of function I've learnt. I have given it a couple of shots on xCode but I know I am creating a mess. Would appreciate any examples with explanations behind the logic.
Thank you
1 Answer
Bharath Chandrashekar
iOS Development with Swift Techdegree Graduate 12,055 Pointsfunc createPlaylist(#playlist:[String:String]) -> (title: String, artist: String, album: String) {
//Creating a tuple from the dictionary given as input to this function
let playlistTuple = (playlist["title"]!,playlist["artist"]!, playlist["album"]!)
return playlistTuple
}
let returnedPlaylistTuple = createPlaylist(playlist: ["title" : "Chak de","artist": "Sukwinder","album": "Patriotic"])
let titleName = returnedPlaylistTuple.title //Prints "Chak de" let artistName = returnedPlaylistTuple.artist //Prints "Sukwinder" let albumName = returnedPlaylistTuple.album //Prints "Patriotic"
Rani Shayto
769 PointsRani Shayto
769 PointsHere is what I have written down in xCode:
func song (#nameOfSong: Dictionary<String,String>) -> (title: String, artist: String) {
return musicDictionary1 // error message: '[String : String]' is not convertible to '(title: String, artist String)'
}