Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

iOS Enumerations and Optionals in Swift Introduction to Optionals Optional Binding

Jonathan Hector
Jonathan Hector
5,225 Points

Not working the same way as the video with the recent update

Here's my code and it doesn't work the same way as you see on the video. That's the swift version I have.

Apple Swift version 3.0.2 (swiftlang-800.0.63 clang-800.0.42.1) Target: x86_64-apple-macosx10.9

Any help would be appreciated

struct Person {
    let firstName: String
    let middleName: String?
    let lastName: String

    func fullName() -> String {
        if middleName == nil {
            return firstName + " " + lastName
        } else {
        return firstName + " " + middleName! + " " + lastName
    }
}

let me = Person(firstName: "Jonathan", middleName: nil, lastName: "Hector")
me.fullName()

let airportCodes = ["CDG": "Charles De Gaule"]
let newYorkAirport = airportCodes["JFK"]

1 Answer

luke jones
luke jones
8,915 Points

Hi Jonathan,

I believe you are missing a curly bracket after the line

return firstName + " " + middleName! + " " + lastName
Jonathan Hector
Jonathan Hector
5,225 Points

thanks really appreciate it.