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 Complex Data Structures Adding Instance Methods

Hey guys, can anyone tell me what to do here? I dont understand what I should do. Thanks!

Hey guys, can anyone explain me what to do? Thanks.

structs.swift
struct Person {
    let firstName: String = "Justus" 
    let lastName: String = "Aberson"
func fullName() -> String {
return firstName + " " + lastName
}


}

let aPerson = Person(firstName: "Justus", lastName: "Aberson")
let myFullName = fullName()

1 Answer

David Papandrew
David Papandrew
8,386 Points

You are close. A couple of changes:

1) Don't provide values for the firstName, lastName properties in the struct (you will pass those values as arguments when you instantiate the struct as "aPerson")

2) The fullName() method call needs to be called on the aPerson object

Here's the corrected code:

struct Person {
    let firstName: String
    let lastName: String

    func fullName() -> String {
      return firstName + " " + lastName
    }
}

let aPerson = Person(firstName: "Justus", lastName: "Alberson")
let myFullName = aPerson.fullName()