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

error message "The value being assigned to fullName must be the result of calling the instance method getFullName()"

struct Person { let firstName: String let lastName: String func getFullName() -> (String){ return "(firstName) (lastName)" } }

let fullName = Person(firstName: "aamir", lastName: "suhial")

let aPerson = fullName.getFullName()

structs.swift
struct Person {
    let firstName: String
    let lastName: String
    func getFullName() -> (String){
        return "\(firstName) \(lastName)"
    }
}

let fullName = Person(firstName: "aamir", lastName: "suhial")

let aPerson = fullName.getFullName()

2 Answers

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

I see a couple of problems here. aPerson should be an instance of a person and the fullName should refer to the full name of the person created. Here is my code. See if it makes more sense when you see it typed out.

  1. The first thing you want to do is create the method to return a string containing the full name of the person. That part was executed brilliantly by you.

  2. The second thing we want to do is create a constant named "aPerson" and create a new instance of a person and assign it to to that constant.

  3. Third, we want to create a new constant named "fullName" and assign it the string that's returned from the method when run on the aPerson we just created.

It seems like somewhere in your logic you got the aPerson and fullName constants mixed up a bit. Happens to us all!

struct Person {
    let firstName: String
    let lastName: String
    func getFullName() -> String{
      return "\(firstName) \(lastName)"
    }
}

let aPerson = Person(firstName: "Jane", lastName: "Doe");
let fullName = aPerson.getFullName();

excellent..... Thank u #Jennifer Nordell