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 trialCollin Keating
1,797 PointsI don't understand how to place a return value, into a variable? In iOS
How to I add the return value to a variable
func greeting(person: String) -> (greeting: String, language: String) {
return (greeting,language)
var result = (greeting,language)
}
greeting("Tom")
2 Answers
Rasmus Rønholt
Courses Plus Student 17,358 PointsHi Collin
So, to declare a variable you use the keyword var followed by blank space and the name of the variable, right?
var someVariable
To give this variable a value you simply add an equals sign and whatever value you like, yes?
var someVariable = "Some Value"
In your case you want to think of greeting("Tom") as if it is already a value that you can assign to the variable.
var result = greeting("Tom")
Now result holds the value returned from the greeting function - understand?
Best of luck with swift/iOS
Jonas Kristensen
2,738 Pointsfunc greeting(person: String) -> (greeting: String, language: String) {
let language = "English"
let greeting = "Hello \(person)"
return (greeting, language)
}
var result = greeting("Tom")
println(result.language)