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 trialJuras Rabačauskas
7,425 PointsObject-Oriented Swift exercise
Hello, can anyone help with this exercise? Thank you
struct Person {
let firstName: String
let lastName: String
func getFullName() -> [String] {
let fullName = firstName + " " + lastName
return fullName
}
}
3 Answers
gianpierovecchi
15,043 PointsAt first sight, you should change the return type of the func in String (without the square brackets). Like this "[String]" it means it's an array of strings. You are just returning a single string.
gianpierovecchi
15,043 PointsNothing wrong with the code, sometime the challenge wants something in another way. Like this simplified way:
struct Person {
let firstName: String
let lastName: String
func getFullName() -> String {
return "\(firstName) \(lastName)"
}
}
Juras Rabačauskas
7,425 PointsThank you!!
MIchael Montoya
3,222 PointsWhy do we have to do the string interpolation? It's not mixing different types right?
gianpierovecchi
15,043 PointsYou are welcome.
Juras Rabačauskas
7,425 PointsJuras Rabačauskas
7,425 PointsThank you for your response. I changed it, but it still did not work