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
Frances Angulo
5,311 PointsString interpolation with functions and strings
Why does this return "John Smith":
func fullName(firstName: String, lastName: String) -> String {
return firstName + " " + lastName
}
fullName("John", "Smith")
but this returns errors such as 'Unresolved Identifier':
func fullName(firstName: String, lastName: String) -> String {
return firstName + " " + lastName
}
println("Your full name is \(fullName("John", "Smith"))")
1 Answer

Khairul Akmal
Courses Plus Student 16,527 Points@Frances Angulo You can't call the function directly. If you want to use string interpolation, I suggest that you create a variable and assign the function on it. Then you can use it without error.
Example:
var fullname = fullName("John", "Smith")
println("Your full name is \(fullname)")
I hope this helps ;D
Frances Angulo
5,311 PointsFrances Angulo
5,311 PointsThanks! This helped, I just didn't want to create the separate line of code. It looks like I can indeed call it in one line, but the interpolation escape character is not necessary.
This worked:
println("Your name is " + fullName("Frances", "Angulo"))
Khairul Akmal
Courses Plus Student 16,527 PointsKhairul Akmal
Courses Plus Student 16,527 PointsFrances Angulo No worries! I'm glad to help and that works too. Like I said if you want to use the string interpolation, that's how it should be done ;D