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 trialPaul M
16,370 PointsObject-Oriented Swift : Challenge Task 2 of 2 Help
I am on Challenge Task 2 of 2, Let's use the struct to create an instance of Person and assign it to a constant named aPerson. Assign any values you want to the first and last name properties. Once you have an instance, call the instance method and assign the full name to a constant named fullName. I have no idea what to do here, can someone help me?
struct Person {
let firstName: String
let lastName: String
func getFullName() -> String {
return "\(firstName) \(lastName)"
}
}
2 Answers
Jennifer Nordell
Treehouse TeacherYou're doing great! You've got it all set up properly to make your Person
. Now you just need to make them!
We do this outside the class definition. Take a look at my solution:
let aPerson = Person(firstName: "Jane", lastName: "Doe")
let fullName = aPerson.getFullName()
So we have a new instance of Person and we're assigning them into the constant aPerson
. Then we make a new constant named fullName
and assign into it the result of running the getFullName
method on this person.
Hope this helps!
Michael Beers
2,035 PointsThanks Jennifer. I got it working! I had String in parentheses after the return arrow. It worked fine in playground. I removed the parentheses and it passed.
Paul M
16,370 PointsPaul M
16,370 PointsThanks! I was unsure that you had to call the function
Michael Beers
2,035 PointsMichael Beers
2,035 PointsI tried this exact solution before finding help
It won't pass and says, " the value being passed assigned to fullName must be the result of calling the instance method getFullName()"
My code runs perfect on playground
Any clues?
Jennifer Nordell
Treehouse TeacherJennifer Nordell
Treehouse TeacherMichael Beers I'm not sure what to tell you. If I take this code and copy/paste it into the challenge... it passes both steps:
Hope you get it working!