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 Parameters and Tuples Tuples

I do not understand why constant and function names are the same. Would you get an error?

For instance:

func greeting (person : String) {
  let greeting = "Hello \(person)
   return greeting
}

1 Answer

Stepan Ulyanin
Stepan Ulyanin
11,318 Points

Functions in every language have signatures - name, parameter list and return value type, you need to make exactly same signature to get an error. Constants and variables can have the same names as function unless they are instance variables and the functions are instance methods, because then you will get an error or unexpected behavior since the compiler uses the names to match with autosynthesised property names.

Thanks Stepan!