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

in Xcode it runs perfectly, but the challengeTask does not accept it. Could you help me what am I doing wrong?

Here is my code, please help me how could I solve this? Cheers! :)

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

        func getFullName() -> (String){

        let fullName = firstName + " " + lastName
        return fullName

    }
}

let aPerson = Person(firstName: "Richard", lastName: "Toth")
let fullName = aPerson.getFullName()

1 Answer

Rodrigo Chousal
Rodrigo Chousal
16,009 Points

Hey Richard,

The logic is spot on, but challenges tend to be very picky so it might work on Xcode but not on the challenge because of a minor (irrelevant) detail. I noticed you surrounded the return type in parenthesis. When writing the return type, we don't surround the type in parenthesis. Try this instead:

struct Person {
    let firstName: String
    let lastName: String

        func getFullName() ->  String { // -> String instead of -> (String)

        let fullName = firstName + " " + lastName
        return fullName

    }
}

let aPerson = Person(firstName: "Richard", lastName: "Toth")
let fullName = aPerson.getFullName()

Hope this helps, Rodrigo

Hi Rodrigo,

thank you so much! I was just so surprised by this, because in the first part of the challenge it accepted it, but in the second part indeed this caused the issue. Anyways, it's good to know, now I have definitely learned this ;)

Thanks again, all the best!