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 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).