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

Maxence Roy
Maxence Roy
8,753 Points

Not sure what to do from here

I'm not sure what to do after I assigned the Person() instance to the aPerson constant?

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

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

let aPerson = Person(firstName: "John", lastName: "MacMiller")

2 Answers

Hey Max,

I was just stuck on this one too, i found the wording quite confusing but eventually got there.

Your first line of code is great and creates the instance of the Person struct. The next thing you need to do is use the 'fullName()' method on that new instance and assign to the new constant.

so my code would look like this:

let aPerson = Person(firstName: "John", lastName: "MacMiller")
let myFullName = aPerson.fullName()

remember we cant use the method directly on the name of the struct (being 'Person') which is why we need to call it on the constant 'aPerson'

hope this helps :)

cheers, Jordan

Maxence Roy
Maxence Roy
8,753 Points

Thanks Jordan! I'm having trouble with object oriented programming but thanks for the tip, I succeeded at the test!

No problem! I'm also finding it challenging (well a good challenge!) anyway good luck!