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

function

function

returns.swift
func greeting(person: String) -> String {
   let name=greeting(person)
    return (Hello person)
}

1 Answer

kirkbyo
kirkbyo
15,791 Points

Hey Rajesh,

I answered someone's question yesterday who had a very similar problem as you right now. I hope it is fine if I copy the answer I gave yesterday.

The question is asking you to return "Hello (Persons Name)". After creating the function is created, you declared an instance of name instead of recalling the function you can just assign the following string (I called mine welcoming)

let welcoming = "Hello \(person)"

After that You can just simply return welcoming.

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

Think of the person argument as a placeholder for whatever string that you pass to it. So when you declare the greeting function you just pass whatever name you would like.

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

greeting("Ozzie")
// return "Hello Ozzie"
greeting("Rajesh")
// return "Hello Rajesh"

I hope I answered your question. If you have another question don't hesitate to ask,

Ozzie