I understand that
var perhapsInt : Int?
This value is automatically set to .None. And the code snippet below confirms that (no compiler errors)
class MyClass {
var num1: Int = 0
var num2: Int?
init(num1: Int) {
self.num1 = num1
}
}
var newClass = MyClass(num1: 5)
newClass.num1
newClass.num2
Do I understand the process of optional initialization correctly? if so, why doesn’t it work when I change num2to let.
I expected the same default options behavior nilwhen used let. Did I miss something?
class MyClass {
var num1: Int = 0
let num2: Int?
init(num1: Int) {
self.num1 = num1
}
}
...
My question is how both of these cases can be true. Shouldn't it be anyway. For any additional values, a value is automatically set .Noneor not.