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

Error is println should not be called directly, it should be in body of function. But it is (I think) ;-)

Error is println should not be called directly, it should be in body of function. But it is (I think) ;-) Works in playground just not on treehouse site...

func greeting() { let halo = "Hello" println("(halo)") }

greeting()

greeting.swift
func greeting() {
let halo = "Hello"
println("\(halo)")
}

greeting()

6 Answers

William Li
PLUS
William Li
Courses Plus Student 26,868 Points

what's the error? I see no error from this code of yours.

I think it's an error in the compiler or whatever is checking the code when I do the test in a browser. It's happened before and thrown me into looking for solutions when code was ok... thx for checking ;-)

OK so here's the error I get in a 'red' panel...

Bummer! You shouldn't call println directly. It needs to be in the body of the function.

It means that you are not giving the answer it expects... it is not a very helpful error message, in fact it doesn't really make sense. I think it simply means that it doesn't want another constant in the function. If you just input:

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

Then you don't have any issues.

William Li
PLUS
William Li
Courses Plus Student 26,868 Points

actually, if you try copy/paste his code to challenge, it'll pass. His code got no problem at all, I think his only mistake is to copy everything over, including the last line greeting(), which part 1 of challenge didn't expect and thus cause error.

That is it. The first part of the two challenges never asks for the greeting function to be called "directly" hence the error "don't call println directly".

That is it. The first part of the two challenges never asks for the greeting function to be called "directly" hence the error "don't call println directly".

Thanks guys, glad I was able to instantiate a conversation at least ;-)