Reputation: 4912
I've only seen people using let
to unwrap optionals.
I was wondering if it is a good practice and I could just as well use var
, or is there something more to it?
What are the pros and cons of using let
versus var
?
Upvotes: 0
Views: 252
Reputation:
As mentioned before, you should always use let
when you can, as it allows compiler do some fancy stuff and thus makes your program run faster.
There is technically nothing wrong with using var, though.
For further reading, please check out this article:
http://www.touch-code-magazine.com/swift-optionals-use-let/
Upvotes: 1
Reputation: 2482
It like usual;
let
is for a constant (you will not be able to modify the value).
The good practice is to always use let when you can (when you don't need to modify the value). It is for optimization purpose and for clarity of the code.
Upvotes: 4