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 trialVictoria M
8,730 PointsError on Xcode when typing function
I am typing the function on to Xcode the way Amit has it but I keep getting two error pop ups that will not let me complete the function. Note I am using Xcode 7.0. I type it like this:
func searchNames (name name: String) -> Bool { let names = ["Amit", "Andrew", "Ben", "Craig", "Dave", "Guil", "Hampton", "Jason", "Joy", "Kenneth", "Nick", "Pasan", "Zac"]
var found = false
for n in names {
if n == names {
found = true
}
}
return found
}
searchNames(name: "John")
and get the following errors: Binary Operator == cannot be applied to operands type "String" and [String] and when I remove one of the = I get the following error Cannot assign to value: 'n' is a 'let' constant
3 Answers
Victoria M
8,730 PointsI think I figured out my error, I was typing if n == names but it needs to be if n == name.
Donald Belliveau
1,057 PointsI have the same issue, it seems to be a changed with Swift 2. Has anyone come across the answer?
Max Jacobsen
Front End Web Development Techdegree Student 3,511 Pointschange the n == names within the if statement to n == name because you want to see as n is going through all the teacher's names in the names array if any of them are equal to your parameter name which is the string you entered.
Donald Belliveau
1,057 PointsDonald Belliveau
1,057 PointsNo you were right the first time, you are looking for n in Names; Names has the list of teachers. I believe this has to do with the changes in Swift 2.