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

Can someone help me with this method challenge?

/* OK THIS ONE WORKS IN MY SWIFT EDITOR BUT THE CHALLENGE EDITOR FAILS WITH THE FOLLOWING: "Make sure you're adding an instance method named getFullName() to the struct definition" */

struct Person { let firstName: String let space: String let lastName: String

func getFullName(firstname first: String, space: String, lastname: String) -> [Person] {

    var storage: [Person] = [] // Array init

    // Now create a new instance of our Object
    let wholeName = Person(firstName: firstName, space: space, lastName: lastName)

    //  Now add this to our array
    storage.append(wholeName)

    return storage

}

} let answer = Person(firstName: "Mic", space: " ", lastName: "Law") // Calling the method.

answer.firstName answer.space answer.lastName

The "space" parameter seems pretty unnecessary, but probably not the issue. Id bet you dont need "firstname" in the method header.

like this maybe?:

func getFullName(first: String, lastname: String) -> [Person] {

var storage: [Person] = [] // Array init

// Now create a new instance of our Object
let wholeName = Person(first: "Bill", space: " ", lastName: "Gates")

//  Now add this to our array
storage.append(wholeName)

return storage

}

3 Answers

Looks like from your error that the func getFullName() is not in the struct (or class) Person.

Like below:

'''swift class Person { let firstName: String let lastName: String

init(firstName: String, lastName: String) {
    self.firstName = firstName
    self.lastName = lastName
}

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

You may have not set the func inside of the struct (or class) Person.

keep getting this error, code seems to work ok on the playground on Xcode

Bummer! Make sure you're adding an instance method named getFullName() to the struct definition

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

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

} ...

keep getting this error, code seems to work ok on the playground on Xcode

Bummer! Make sure you're adding an instance method named getFullName() to the struct definition

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

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

} ...