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

swift 3.0 Method Instince

Need some help not sure what I'm Missing or doing wrong

Challenge Task 1 of 2

Given the struct below in the editor, we want to add a method that returns the person’s full name. Declare a method named fullName() that returns a string containing the person’s full name. Note: Make sure to allow for a space between the first and last name Bummer! Make sure you're adding an instance method named fullName() to the struct definition Restart Get Help Recheck work structs.swift

1 struct Person { 2 let firstName: String 3 let lastName: String 4 func fullName( Name firstName: String, Last lastName: String) -> String [Person] { 5 return fullName(Name: " ", Last: " ") 6

7 } 8 }

structs.swift
struct Person {
    let firstName: String
    let lastName: String
    func fullName( Name firstName: String, Last lastName: String) -> String [Person] {
        return fullName(Name: " ", Last: " ")

    }
}

3 Answers

You don't need to add any parameters to the fullName function. All the function needs to know is that it will be returning a string.

struct Person {
    let firstName: String
    let lastName: String

// Challenge 1
    func fullName() -> String{
      return "\(firstName) \(lastName)"
    }
}
// Challenge 2
let aPerson = Person(firstName: "Jane", lastName: "Doe");
let fullName = aPerson.fullName()

literally copied and pasted this code and it doesn't work.

Awesome Thanks. Yeah was adding to much that wasent needed. Thanks

The second challenge not passing not sure whats wrong?