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!
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

Phil Hanson
764 PointsReturn issues in Swift
This doesn't work for me, all kinds of weird things happening. I have:
func fullName(firstName: String, lastName: String) -> String {
return firstName + lastName
}
When I call this with fullName I get this weirdness.
fullName(firstName: String, lastName: String)
Except firstName: String are editable and only String for the second part is??? What is going on.
I should be able to have this:
func fullName(firstName: String, lastName: String) -> String {
return firstName + lastName
}
print(fullName("Phil","Hanson"))
But this doesn't work.
1 Answer

Iman Mk
6,223 PointsHi Phil,
All methods called on an object use parameter names except for the first parameter. So your print function would be:
print(fullName("Phil", lastName: "Hanson"))
Also you can have external parameter names to use everywhere if you like to:
func fullName( first firstName: String, second lastName: String) -> String {
return firstName + lastName
}
print(fullName(first: "Phil", second: "Hanson"))
Let me know if you have any questions!
Phil Hanson
764 PointsPhil Hanson
764 PointsJeez, I did it all right but because I didn't know first parameter didn't use a name, I was freaking out. Works perfect now :(
That seems like a weird design...
Iman Mk
6,223 PointsIman Mk
6,223 PointsAwesome! It is for a reason to work better with obj-c and for another factor. btw for the answer that helped you the best there is an upvote button that lets the commenter know his/her answer was helpful :)