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 Build a Simple iPhone App with Swift Creating a Data Model Finishing Up Our Model

Usage of var vs let

Would it be preferable to use let for the temporary variables, such as the random number and the number of facts?

1 Answer

Jason Wayne
Jason Wayne
11,688 Points

Not too sure about that, using let refers the variable to be a constant. By generating a random fact number, the value of the constant will always be different. Using a var might be more appropriate.

Use let when the variable value is never changed. A good example would be setting the API Key to a constant.

however, isn't the random number constant for that iteration of the code?

Jason Wayne
Jason Wayne
11,688 Points

That's true. Usually the scenario is using variables instead of constants if the value is never the same.