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

Ryan Maneo
Ryan Maneo
4,342 Points

So confused

What on earth do I do? Do I make a function? Do I just make a constant containing (firstName: String, lastName: String)? The instructions weren't clear...

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

    func getFullName() -> (String, String) {

    return (firstName: String, lastName: String)
    }
}

2 Answers

Hi Ryan,

You're pretty much there, but you've not quite nailed the way you want to return the string.

You want to return a single string like "Steve Hunter" which is made up of the two stored properties in the struct, firstName and lastName. The easiest way to do that is by interpolation, "\(firstName) \(lastName)", but you could use concatenation, firstName + " " + lastName.

So, amend your method to return a single string, then return one of the composed strings above.

Make sense? Let me know how you get on. Shout if you need more help. :+1:

Steve.

Ryan Maneo
Ryan Maneo
4,342 Points

I got this far:

struct Person { let firstName: String let lastName: String

func getFullName() -> (String) {

return firstName + " " + lastName
}

}

let aPerson = Person(firstName: "Ryan", lastName: "Minnick") let fullName = aPerson

But the last part "let aPerson = Person(firstName: "Ryan", lastName: "Minnick") let fullName = aPerson " is returning an error and won't work...

You need to call your method on the aPerson object.

let fullName = aPerson.getFullName()

Let me know how you get on.

Steve.

Ryan Maneo
Ryan Maneo
4,342 Points

Okay... I tend to get confused a lot because a lot of the phrases he uses like "calling" or appending change a bit depending on the problem... so I constantly lose touch as to what he means. Thank you for clarifying.