I just started to learn Swift 3. I am a little bit experienced in C++ but I am a bit confused when it comes to constants in Swift.
Following code:
class Auto {
var maxKmH:Int = 50;
var color:String = "green";
}
class Autohaus
{
public var Autos:[Auto] = [];
let amount:Int;
func addAutos()
{
for i in 0..<self.amount{
var car = Auto(); // warning to replace VAR with LET ???
Autos.append(car);
}
}
}
So Xcode advises me to use let instead of var in the following line
var car = Auto();
When I do that, the warning disappears HOWEVER I can still change the object (for example the attributes).
This confuses me a bit, since a constant actually can be changed? Why do I need let then, if it's mutable?
Thanks guys!