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

I need help on object-Oriented Swift 2.0 getfullName()

How to solve this code

structs.swift
struct Person {
    let firstName: String
    let lastName: String
}
Jason Anders
Jason Anders
Treehouse Moderator 145,860 Points

The code included just has the starter code for the challenge... could you include what code you have tried to solve the challenge. This way we can help you troubleshoot. :dizzy:

1 Answer

David Papandrew
David Papandrew
8,386 Points

Hi Anan,

You need to create a method within the struct called getFullName that returns a string with firstName and lastName.

Here is the code for Step 1 if you need help with that. Hopefully that is enough to get you started in the right direction. Step 2 will have you create an instance of Person and then call the getFullName function on that object.

struct Person {
    let firstName: String
    let lastName: String

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

Thank you dear ,