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!

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 Optionals What is an Optional?

Zachary Goforth
Zachary Goforth
748 Points

What 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") 

1 Answer

Jhoan Arango
Jhoan Arango
14,575 Points

Hello 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
Zachary Goforth
748 Points

I 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?