Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

iOS Swift Functions and Optionals Functions Creating a Function

"You shouldn't call println directly, it should be in the body of function" problem

So I'm doing everything like in video: creating a function called greeting creating a constant that is a statement of Hello creating a println line, which will print the statement closing the function and executing it

Yet it still says that println has to be in the function. So it is not? Everything works like a charm in Xcode (except the println which has to be changed to print).

Please help me so I could move to next challenges. Cheers Grzegorz

greeting.swift
func greeting() {
  var statement = "Hello"
  println("\(statement)")
  }
greeting()

Oh and I was just messing with constant and variable, but in my code there is let instead of var. But it doesn't mater in this case, right?

3 Answers

Sorry I have it now, found out I could view the challenge. This is the correct answer judging from the challenge it directed me to.

func greeting(){
  println("Hello")
}

greeting()

You don't need to create a variable to store the word hello, it just asks you to print it out using println and then call the function. Hope this helps.

Try just doing println(statement) rather than the concatenation

Thanks for help! Problem solved, i did what you said + haven't executed the function (which was another task).