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

Instance Methods Challenge

Hello, can anyone help me out with this challenge, thank you

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

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

let aPerson = Person(firstName: Juras, lastName: Rabacauskas)
let fullName = aPerson.getFullName()

2 Answers

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

You're doing great! The problem is in this line:

let aPerson = Person(firstName: Juras, lastName: Rabacauskas)

You simply forgot to put the names Juras in Rabacauskas in quotes. So it thinks those are variable names. And since it can't find any variables named that, it doesn't know what to do so you get a compiler error. Try this line:

let aPerson = Person(firstName: "Juras", lastName: "Rabacauskas")

You should be able to move to the next step after this small change. Good luck! :smile:

Jennifer Nordell
seal-mask
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Here was the code I used to pass step 2. Take a look:

struct Person {
    let firstName: String
    let lastName: String

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

let aPerson = Person(firstName: "Juras", lastName: "Rabacauskas")
let fullName = aPerson.getFullName()

Thanks!! Now thats a confidence boost! :D

It didn't workout - I got an error "The value being assigned to fullName must be the result of calling the instance method getFullName()". Any more tips? Thank you very much.

Thank you, I dont know why for me it's not working - I tried it and got "The value being assigned to fullName must be the result of calling the instance method getFullName()" error.