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 Functions Function Return Types

Jake N
Jake N
612 Points

lost

im not sure how to solve this one

returns.swift
func greeting(person: String) -> (greeting: String, language: string) {
let language = "english"
let greeting = "Hello \(Tom)"
return (greeting, language)
}

3 Answers

Chris Shaw
Chris Shaw
26,676 Points

Hi Jake,

You have a first problems with your code.

  1. In your return type, the type string set for language is incorrect, it should have a capital S
  2. the e in English needs to be capital
  3. your greeting constant needs to refer to the parameter person instead of Tom which is invalid
func greeting(person: String) -> (greeting: String, language: String) {
  let language = "English"
  let greeting = "Hello \(person)"

  return (greeting, language)
}

Happy coding!

Stone Preston
Stone Preston
42,016 Points

his code he posted is actually for the tuples challenge, however the challenge he is on that this question is linked to is for return types.

Stone Preston
Stone Preston
42,016 Points

I answered your other question concerning this challenge, but ill include it below for completeness in case someone else stumbles across this in the future

your code is similar for the code necessary for a different challenge. However the challenge you linked to is not that one. Did you get your code from another forum post perhaps? That code is for a tuples challenge, this challenge is on return types.

the challenge states Modify the definition of the function named greeting to return a String and replace the println statement with a return statement. The function should return a greeting. For example, if you pass in a string "Tom" then the return string would be: "Hello Tom".

the challenge initially has the following code:

func greeting(person: String) {
    println("Hello \(person)")
}

it needs to return a string and you need to return the string, not print it

the swift eBook states:

You indicate the function’s return type with the return arrow -> (a hyphen followed by a right angle bracket), which is followed by the name of the type to return.

func greeting(person: String) -> String {
    return "Hello \(person)"
}
Jake N
Jake N
612 Points

thanks for the help guys