I'm facing an issue with optionals
and need a deeper understanding of the below scenario.
Here is the code,
class X {
let b: Int! //not working
let c: Int? //not working
var q: Int! //working
var r: Int? //working
}
let x = X()
x.a
In the above code, I've simply created 4 combinations of let
and var
along with optional
and implicitly unwrapped optional
.
The above code gives me the below compiler error:
Return from initializer without initializing all stored properties
Issue:
Why is it necessary to assign values of b
and c
in init
if they both have nil as the default values? And if it is required, why is it not mandatory to assign q
and r
in init
?.