Difference between type and explicitly expanded type in Swift

This really puzzles me: what is the difference between an implicitly unwrapped optional and the type itself?

For instance,

var s:String!
var s2: String

Don't these two exactly match? They represent a String that cannot be nil, so why on earth do we need! thing?

+4
source share
1 answer

Implicitly expanded optional parameter optional , in fact you can assign a valuenil

var s: String! = nil

, , ? , , , , , , .

: , , , - :

let s: String! = nil
var s1: String = s // Execution was interrupted, reason: EXC_BAD_INSTRUCTION ...

: ? , .

, (, , )

+7
source

All Articles