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

Jaron Trotter
Jaron Trotter
11,472 Points

How do I write this code

I'm trying to write a simple function code. It's saying I can't call on the println directly. It needs to be inside the body.

greeting.swift
func greeting() {

let right = "Hello"

println("right")
}


greeting ()

2 Answers

Tobias Helmrich
Tobias Helmrich
31,601 Points

Hey there,

I think you're overthinking it a bit by assigning "Hello" to a constant which you don't really need to. However if you do, you have to remove the quotes around "right" in your println function because right now you're printing out the String "right" instead of the right constant.

If you print it out without an extra constant it should look like this:

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

greeting()

Also note that in Swift 2 println became deprecated and that you have to use print now.

I hope that helps! :)

Jaron Trotter
Jaron Trotter
11,472 Points

Thank you for your help!