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 Function Return Types

Frances Angulo
Frances Angulo
5,311 Points

Return vs. Println

What was the benefit of returning the value over printing it? If you print it, does it form as a string so that the calculation is not as versatile with other uses? Kind of like a data type in an Excel sheet?

1 Answer

Chris Shaw
Chris Shaw
26,676 Points

Hi Frances,

The println function should always be considered as a way to debug your code as it doesn't store the value anywhere for you to use later on, the benefit of it is to print data to the Xcode console to fix issues. Once you've completed your debugging it's best practice to remove any rouge println calls to ensure the best performance of your app is achieve.

As for the return keyword you should always use it anywhere a function has a return type specified which is anything other than Void.

Frances Angulo
Frances Angulo
5,311 Points

So if you wanted to have something print out on the screen for a user, you would not use println? It's mainly intended to test the results of a line of code?

Chris Shaw
Chris Shaw
26,676 Points

Correct, if you wish to output data onto a users screen you will need to use a UITextView or a multi-line UILabel view.