6 ms·
I think the author misses the point of the `let` keyword. It's not meant as the equivalent of declaring constants in Objective-C; they're main purpose isn't to
by andrewdanks 12y ago
I think the author misses the point of the `let` keyword. It's not meant as the equivalent of declaring constants in Objective-C; they're main purpose isn't to be global and static like constants.
- rubiquity 12y agoAnd yet you've managed to shed no light on how constants should be used in Swift.
- andrewmunsell 12y agoTo shed some light on the practice of using `let` vs. `var`, an excerpt from the book by Apple: “If a stored value in your code is not going to change, always declare it as a constant with the let keyword. Use variables only for storing values that need to be able to change.” Excerpt From: Apple Inc. “The Swift Programming Language.” iBooks. https://itun.es/us/jEUH0.l https://itun.es/us/jEUH0.l
- jquave 12y agoThanks Andrew, I am updating the posts as I learn more. We're all still learning.
- gress 12y agoLet is fine for defining constants, but it should also be used whenever possible for two reasons: 1. It gives you additional safety against accidental reassignment. 2. It gives the compiler a major optimization hint since the value is not a variable.