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

jon kelson
jon kelson
5,149 Points

hi please would someone help thanks

greeting(person: String) -> (greeting: String, language: String) { let language = "English" let greeting = "Hello (person)" var result = greeting(Person: "Tom")​ return (greeting: greeting, language: language) }

tuples.swift
 greeting(person: String) -> (greeting: String, language: String) {
    let language = "English"
    let greeting = "Hello \(person)"
var result = greeting(Person: "Tom")
    return (greeting: greeting, language: language)
}

1 Answer

Hi, this is the code that worked for me

func greeting (person: String) -> (greeting: String, language: String) {
    let language = "English"
    let greeting = "Hello \(person)"
    return (greeting: greeting, language: language)
}

So basically you need to remove the variable (var) result because its: a) redundant since you are already returning greeting and language when you execute the function b) because its modifying "greeting" which is a "let" and can't be modified

in the next step of the challenge you might use that line of code to print out the result, as follows (I don't know the next step, so I'm guessing)

func greeting (person: String) -> (greeting: String, language: String) {
    let language = "English"
    let greeting = "Hello \(person)"
    return (greeting: greeting, language: language)
}

var result = greeting("Tom")   

println(result)

notice that you don't need to include (person:"Tom") but just "Tom", because theres no # in the input parameter name of the function