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

Valeria Ruiz
Valeria Ruiz
948 Points

methods

Hi guys, any ideas on how to resolve this step?

Thanks so much !

structs.swift
struct Person {
    let firstName: String
    let lastName: String
func getFullName() -> String {
    return "\(firstName) \(lastName)"
}}
let aPerson = ("Val", "Smith")
getFullName.append(aPerson)

1 Answer

Zachary Betz
Zachary Betz
10,413 Points

Answer

struct Person {
    let firstName: String
    let lastName: String

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

let aPerson = Person(firstName: "Val", lastName: "Smith")
let fullName = aPerson.getFullName()

Explanation

You were passing the Val and Smith strings as arguments, but were not initializing the Person struct, i.e.

Person(firstName: "Val", lastName: "Smith")

getFullName() is a method of the Person struct, so to call it, you need to prefix the method with your initialized variable, i.e.

aPerson.getFullName()

and then assign it to the fullName variable.