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

Why am I getting Type 'String' does not conform to protocol 'SequenceType'?

import UIKit

func searchNames (name names: String) -> Bool { _ = ["Amit", "Andrew", "Ben", "Craig", "Dave", "Guil", "Hampton", "Jason", "Joy", "Kenneth", "Nick", "Pasan", "Zac"]

var found = false

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

}

return found }

searchNames(name: "John")

1 Answer

Tommy Choe
Tommy Choe
38,156 Points

Hey Javid,

in your for in loop you should search within the array that you created, not within the passed parameter, "names". In your if statement, this is where you should be checking if "n" is equal to the passed parameter, "names". Also I would assign the array to a variable/constant so that you can refer to it. This is what I did:

func searchNames (name names: String) -> Bool { let instructors = ["Amit", "Andrew", "Ben", "Craig", "Dave", "Guil", "Hampton", "Jason", "Joy", "Kenneth", "Nick", "Pasan", "Zac"]

    var found = false

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

    }

    return found }

searchNames(name: "Craig")

Hope that helps!