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

Eli MBS
Eli MBS
1,158 Points

swift object oriented programming

Object-Oriented Programming seems quite difficult to me... I don't understand this challenge and would be glad if someone could help me a little bit with it :)

structs.swift
struct Person {
    let firstName: String
    let lastName: String
    func getFullName(firstName: String, lastName: String) {
        return "\(firstName) \(lastName)"
}

1 Answer

Anjali Pasupathy
Anjali Pasupathy
28,883 Points

You've nearly got the function right. You need to specify the return type, and you need to add in a closing curly bracket. You also shouldn't have any parameters passed into the function. You're writing the function inside the struct, so the function already knows that firstName and lastName exist.

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

I hope this helps!

thanks