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 Object-Oriented Swift 2.0 Complex Data Structures Adding Instance Methods

Object-Oriented Swift exercise

Hello, can anyone help with this exercise? Thank you

structs.swift
struct Person {
    let firstName: String
    let lastName: String

    func getFullName() -> [String] {
    let fullName = firstName + " " + lastName
    return fullName
    }
}

3 Answers

At first sight, you should change the return type of the func in String (without the square brackets). Like this "[String]" it means it's an array of strings. You are just returning a single string.

Thank you for your response. I changed it, but it still did not work

Nothing wrong with the code, sometime the challenge wants something in another way. Like this simplified way:

struct Person {
    let firstName: String
    let lastName: String

    func getFullName() -> String {
        return "\(firstName) \(lastName)"
    }
}

Thank you!!

MIchael Montoya
MIchael Montoya
3,222 Points

Why do we have to do the string interpolation? It's not mixing different types right?

You are welcome.