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

Bekzod Rakhmatov
Bekzod Rakhmatov
7,419 Points

I could not understand what the method is Please help me!

Method and Function brought me to confuse each other

structs.swift
struct Person {
    let firstName: String
    let lastName: String
    func fullName(Name name: String) -> [Person] {
        var result = [Person]()
        return result
    }
}

1 Answer

Maria Angelica Dadalt
Maria Angelica Dadalt
6,197 Points

I know it's hard, but you need to read the instructions closely, review the videos and read the Swift guidelines to help you understand more about what the hell everyone is talking about. I know I get confused a lot in this course, but doing all of this helps.

By the way, methods and functions kind of mean the same thing. Parsan talks about this in his first video about functions, I believe.

So here is where you went wrong. The instruction doesn't ask for parameters in your function, but you do need to return a string. So the set up for the method should look like this:

func fullName() -> String {
}

Now you need to set up a concatenation or interpolation of the string to return the full name.

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

or

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

Now you have to create an instance of Person using a let called aPerson with values of your choice:

let aPerson = Person(firstName: "Maria Angelica", lastName: "Dadalt")

And finally, you have to call on the method (or function, whichever you prefer), using the instance you created with a dot notation.

let myFullName = aPerson.fullName()

I hope this could help you!

Bekzod Rakhmatov
Bekzod Rakhmatov
7,419 Points

Thank you so much Maria Angelica I am not native English speaker so It is a bit difficult to understand the instruction but the Community is really helping me so much