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 trialZachary Goforth
748 PointsWhat is the expected after 'if' condition?
I'm on the Task Challenge 2 (of optionals) and when I put my code I got this error... swift_lint.swift:16:33: error: expected '{' after 'if' condition if let result = names("Doc")
I've used if-let function thing but is my code in the wrong place, am I missing something, or am I not even close?
func search(#name: String) -> String? {
let names = ["Doc","Grumpy","Happy","Sleepy","Bashful","Sneezy","Dopey"]
for n in names {
if n == name {
return n
}
}
return nil
if let result = names("Doc")
println("Found")
}
1 Answer
Jhoan Arango
14,575 PointsHello Zachary : You are not calling the function. Instead of using names use **
if let result = search(name: "Doc").
If you need a better explanation let me know.
Good luck.
Zachary Goforth
748 PointsZachary Goforth
748 PointsI placed the code under the return nil and recieved this error...
swift_lint.swift:16:40: error: expected '{' after 'if' condition if let result = search(name: "Doc") ^
Am a placing the code in the wrong place or is it something else?