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

Jordan Nilsson
Jordan Nilsson
1,409 Points

How do I complete task 2 of this challenge?

I understand how to create a variable and to name it result, but I don't understand the part about assigning it to the tuple. What do I do to complete this task?

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

2 Answers

Jhoan Arango
Jhoan Arango
14,575 Points

You are close, just put the variable outside the function. And call the function to that variable.

Here is the complete answer

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

var result = greeting("Tom")
println("\(result.language)")

The question asks to create a variable name result and store the value returned by the function greeting.

var result = greeting("Tom")
Jordan Nilsson
Jordan Nilsson
1,409 Points

I really appreciate the time you took to help me! Thank you so much!

Most welcome.

Jordan Nilsson
Jordan Nilsson
1,409 Points

Maulik, do you know the opposite of ==?

The Opposite of == is !=

let number = 3
if number != 4 {
     println("The number is not equal to 4.")
}

The above block of code will print "The number is not equal to 4." because the var number is not equal to 4