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

John Salamon
John Salamon
515 Points

Shouldn't call the println directly should be in the body of your function

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

} greeting()

Getting an error that 'Should not call println directly should be in the body of your function.....error

The example code is very different and the exercise badly matches the previous video, can anyone help..... Functions

Marcio Mello
Marcio Mello
7,861 Points

I don't think you need the quotes (") inside the println function.

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

3 Answers

Marcio Mello
Marcio Mello
7,861 Points

I am glad it did work on Xcode. In the end, that is what matters ;) As for workspaces, I have not tried Swift in it yet. Sorry that I can not help with that issue.

John Salamon
John Salamon
515 Points

Sorry to be a bother... so I tried this

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

and now I get 'Your code could not be compiled'

swift_lint.swift:8:20: error: use of unresolved identifier 'Hello' let greeting = Hello

Thanks for any help ;)

John Salamon
John Salamon
515 Points

This is really strange because this works fine for me in Xcode .....

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

} greeting() greeting() greeting()

But it will not work on the treehouse site for the exercise???