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

Benjamin Tinsley
Benjamin Tinsley
3,334 Points

Why wont my solution pass?

I am getting the error Bummer! Make sure your function does not take any parameters and returns a String which is not very helpful because my function does not take any parameters and it both explicitly and implicitly returns a string.

If I run this in Xcode, it returns the name I give it as expected. Why wont Treehouse? Seems like there is one very specific way to get it to pass and I'm just not seeing what that is.

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

    func fullName() -> (String) {
      return "\(firstName) \(lastName)"
    }
}
let ralph = Person(firstName: "Ralph", lastName: "Harris")
print( ralph.fullName() )

// prints "Ralph Harris"

1 Answer

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

Hi there! You've put the return type in parentheses which is causing the challenge to fail. If I remove your bottom 2 test lines and then remove the parentheses from (String), your code passes.

Take a look:

  func fullName() -> String {  //note the removal of the parentheses around String
      return "\(firstName) \(lastName)"
    }
}

Hope this helps! :sparkles:

Benjamin Tinsley
Benjamin Tinsley
3,334 Points

Perfect, thanks Jennifer. I just did that myself and it worked. Glad you helped!