First, forgive me if my questions are completely off base. I've only recently started using Swift. I searched for similar questions without finding anything, but me search skills in Apple's forums have let me down many times in the past. If this topic has been discussed before, I'm happy just to have a link in reply.
The Swift compiler can always tell when a variable is being defined because there is either an immediate assignment from which type can be inferred, or there is an explicit type provided after a ":". The presence of an assignment or a colon following a name not previously seen unambiguously indicates creation of a variable or possibly a constant.
Why do we need the keyword "var" at all. I must be missing something obvious, but under what situation does the keyword "var" add any information the compiler did not already have or could infer?
For local variables, I'm fairly confident that "var" and "let" add no information the compiler doesn't already have. Xcode tells me when a variable is not mutated within scope and suggests I change the declaration to "let". If I could omit the "var" keyword, the compiler would be free to identify unmutated values and treat them as constants all on its own. IN other words, if Xcode can tell me I'm doing it wrong, then Xcode could have done it for me.
For class properties and globals, I can see that "let" differentiates between constants and variables. Why not just assume each global and each property is "var" unless I specify "let". (And I'm not sure why "let" is a better keyword than "const" in this context)
In summary, why can't we omit "var" in every case and use "let" exclusively for constants that have a scope indeterminate to the compiler? As far as I can tell, right now, only globals (which should be discouraged) and immutable properties require "let" to give the compiler information it didn't already have.
Again, I apologize if I'm way off. I can't help thinking I'm missing something obvious. I have used LLVM extensively to build "compilers", and I've looked at the Swift grammar, and I just don't see why we "need" "var".