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


Eliot Murton
Eliot Murton
7,315 Points

Xcode functions, Parameters, Tuples and Dictionaries. Please help.

I am trying to complete one of the extra credit tasks: "Write a function that accepts a Dictionary as parameter and returns a named tuple. The Dictionary should contain the following keys: title, artist, album." Here is what I have come up with so far.

func searchMusic (#musicInfo: Dictionary) -> (found: Bool,description: String) {

    let music = [

        [ "Title": "96 Quite Bitter Beings", "Artist": "CKY", "Album": "Camp Kill Yourself, Vol.1"],

        [ "Title": "Psychosocial", "Artist": "Slipknot", "Album": "All Hope Is Gone"],

        [ "Title": "Gasolina", "Artist": "Daddy Yankee", "Album": "Barrio Fino"],

        [ "Title": "Where Them Girls At", "Artist": "David Guetta", "Album": "Where Them Girls At"],

        [ "Title": "Who's That Chick", "Artist": "David Guetta", "Album": "Where Them Girls At"],

    var found = (false, "This music is not found")

    for m in music {
        if m == musicInfo {
            found = (true,"This music is found)")

    return (title,artist,album)


It took me ages to make this code without it having any errors. Now I cant find a way to enter the input to get the return that I want. I tried the blow but this did not work:

let (found,description) = searchMusic (["Title": "96 Quite Bitter Beings", "Artist": "CKY", "Album": "Camp Kill Yourself, Vol.1"])

let result = searchMusic(["Title": "96 Quite Bitter Beings", "Artist": "CKY", "Album": "Camp Kill Yourself, Vol.1"])

ideally i would like a way to enter part of a dictionary and get the full desired result. I am now lost. If any body can give me some help I would really appreciate it!

1 Answer

Guled Ahmed
Guled Ahmed
12,806 Points

I took a look at your function quite closely and found a few issues. First I'd like to point out that a parameter needs a specific type, you did specify the type by putting "Dictionary", but it needs more details. I noticed your Dictionary requires a set of strings so to specify that the parameter needs a dictionary that has strings in it you must do this:

func searchMusic (#musicInfo: Dictionary<String,String>) 

Here I am specifying that I want a dictionary with a key that is a string and a value that is a string. You may change this as you wish.

Second, though I haven't looked closely at this extra credit myself, but your function is suppose to return a boolean and a string, a count of two return items, but instead your function currently returns 3 items.

// What your function needs to return 
 -> (found: Bool,description: String) {

// What you are actually trying to return
return (title,artist,album)

So what you need to do is specify that your function will return 3 items instead of 2 like so:

 -> (Title: String , Artist: String, Album:String)

This should help you towards going in the right direction to complete the extra credit. If you need any further help just let me know.