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

iOS Swift Functions and Optionals Parameters and Tuples Tuples

boris said
boris said
3,607 Points

I get this strange error message and i don't know what it means please help

here is my code

func searchNames (#names: String) -> Bool {
    let names = ["Benny", "Tom", "Chris", "Phage"]

    var found = false

    for n in names {
        if n == names {
            found = true
        }
    }




    return found

}

searchNames(names: "Tom")

1 Answer

Maximiliane Quel
PLUS
Maximiliane Quel
Courses Plus Student 55,489 Points

Hi,

you are calling both your parameter and the array "names". You need to rename one of those, so your code reads something like this:

func searchNames (#name: String) -> Bool {
    let names = ["Benny", "Tom", "Chris", "Phage"]

    var found = false

    for n in names {
        if n == name {
            found = true
        }
    }

    return found

}

searchNames(name: "Tom")

Hope that helps