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

I understand how to code but what's the error?

error: swift_lint.swift:15:16: error: '(StringLiteralConvertible) -> $T2' is not identical to 'String' if let n = name ("Snow White"){ ^

search.swift
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 n = name ("Snow White"){
    println("Found")
    }
}

2 Answers

Jhoan Arango
Jhoan Arango
14,575 Points

Hey Josh:

You are not calling the function.

This is what you are looking for to pass the challenge.

func search(name 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 = search(name: "Doc") {
    println("Found")
}

The challenge wants you to use the if let statement, with a constant named "result", and then call the function with "Doc".

I was looking at the track for the rest of IOS development. I saw that there are teachers. Why?

There are two different teachers.

Jhoan Arango
Jhoan Arango
14,575 Points

Well, there are different. Amit, was the initial teacher for the Swift 1.2 courses, but for Swift 2.0 Pasan took over, because Amit is no longer teaching, he is now in a different position in treehouse.