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!

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

Fedor Andreev
Fedor Andreev
11,203 Points

What is the difference between return and ->

Now I'm really confused.

I understand that return means that you are telling the function, "Hey after you are done adding 1+1 I want you to return the answer to me".

But what the **** is -> return integer type? .. To return something more???

2 Answers

Erik Uusitalo
Erik Uusitalo
8,096 Points

-> is telling the function what type (int, float, double) you want the function to return.

Stepan Ulyanin
Stepan Ulyanin
11,318 Points

Every function has a unique signature which includes the name of the function, parameter list and the return type:

func calculateArea(width: Int, height: Int) -> Int {
       return width * height

Here where you specify the name of the function and parameters you have to specify what the function WILL return. You have to predict, something like that: "Ok I have two integers as parameters and I am going to return the multiplication of these integers which is also going to be an integer... AHA, my return type should be Int", so you go back to the declaration of the function and add -> Int, hope that helps