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 trial

iOS Swift Functions and Optionals Parameters and Tuples Tuples

Robert Vazquez
Robert Vazquez
1,782 Points

How to change the value in Tuples in iOS

How do you Assign the return value of the "Greeting Func" to "Result" after making the variable named "result"

Thanks

tuples.swift
func greeting(person: String) -> (greeting: String, language: String) {
    let language = "English"
    let greeting = "Hello \(person)"

      var result 

    return (greeting, language)
}

1 Answer

L B
L B
28,323 Points

You are trying to create a variable in a function that you want to call. This is incorrect. You want to create a new variable outside the code blocks:

//Task One
func greeting(person: String) -> (greeting: String, language: String) {
    let language = "English"
    let greeting = "Hello \(person)"
    return (greeting, language)
}
//Task Two
var result = greeting("Tom")
//Look at task one func. It wants a person of type String as input. 
//So I put Tom in " " to parse a string.


//Task Three
println(result.language)
//You have already created a result variable. But task asks you to access the language part of it. 
//So you use . plus the the value you want to access.
Robert Vazquez
Robert Vazquez
1,782 Points

Thanks a lot L B after I looked at your example I saw what I needed to do for the 2nd task I really appreciated it for your time to help me out

thanks again