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 trialRyan Maneo
4,342 PointsSo confused
What on earth do I do? Do I make a function? Do I just make a constant containing (firstName: String, lastName: String)? The instructions weren't clear...
struct Person {
let firstName: String
let lastName: String
func getFullName() -> (String, String) {
return (firstName: String, lastName: String)
}
}
2 Answers
Steve Hunter
57,712 PointsHi Ryan,
You're pretty much there, but you've not quite nailed the way you want to return the string.
You want to return a single string like "Steve Hunter" which is made up of the two stored properties in the struct, firstName
and lastName
. The easiest way to do that is by interpolation, "\(firstName) \(lastName)
", but you could use concatenation, firstName +
" " + lastName
.
So, amend your method to return a single string, then return one of the composed strings above.
Make sense? Let me know how you get on. Shout if you need more help.
Steve.
Steve Hunter
57,712 PointsYou need to call your method on the aPerson object.
let fullName = aPerson.getFullName()
Let me know how you get on.
Steve.
Ryan Maneo
4,342 PointsOkay... I tend to get confused a lot because a lot of the phrases he uses like "calling" or appending change a bit depending on the problem... so I constantly lose touch as to what he means. Thank you for clarifying.
Ryan Maneo
4,342 PointsRyan Maneo
4,342 PointsI got this far:
struct Person { let firstName: String let lastName: String
}
let aPerson = Person(firstName: "Ryan", lastName: "Minnick") let fullName = aPerson
But the last part "let aPerson = Person(firstName: "Ryan", lastName: "Minnick") let fullName = aPerson " is returning an error and won't work...