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

I have tried and tried again but my code doesn't seem right, what is going wrong?

To make a method you have to specify the stringent,double,etc. to finish it but the challenge doesn't give me anything to go on. What should I be seeing that I'm not?

structs.swift
struct Person {
    let firstName: String
    let lastName: String
}
let fullName = Person(firstName: first?Name, lastName: Last?Name)

Yeah I just don't know

Kristof Kocsis
Kristof Kocsis
15,455 Points

A method is a function within a struct or class. So you have to declare a function inside the struct that returns a string.

1 Answer

Kristof Kocsis
Kristof Kocsis
15,455 Points

In the comment I explained how to do it and now here is the actual code.

struct Person {
    let firstName: String
    let lastName: String

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

Thank you so much I have a problem with which makes it hard to think when under stress. the condition is called "Life". But still thank you