I wanted to bring up the current magical behavior of Optional auto initialization to nil when using
Currently in swift you can declare an Optional
variable in this way
var foo: String? print(foo) // prints nil
swift will automatically assign
.none to the value. The above is somewhat equivalent to the below code.
var foo: String? = nil // .none print(foo) // prints nil
but this behavior is only available when using
?. The below does not work.
var someValue11:Optional<String> // print(someValue11) // error: variable 'someValue11' used before being initialized
I think this behavior is confusing specially when dealing with implicit unwrapped optional.
var someValue33:String! _ = someValue33 + "?") // Boom Crash. No different from an uninitialized variable error
I propose that we deprecate this to make swift more consistent.
var foo: String? // print(foo) // error: variable 'foo' used before being initialized. <Insert fixit here to add = nil>
What does the community think?