1. As as! As The difference
One, as
From the Chinese API: This value is matched only if the type of a value is consistent with the specified type at runtime (runtime) and the right of the as mode-or subclass of that type. If the match succeeds, the type of the value being matched is converted to as the pattern specified on the left side of the pattern.
The first is that the runtime does not say much, it is important that as the application conditions have 2 kinds of situations:
1, same as "as" to the right type
2, is the subclass of the right type (this is called upward transformation in Java)
The case code is as follows:
Two, as!
In the second case 2, the subclass of the right type will report an error if it encounters the parent class of the right type of the as left type! (as can not be used in the parent class, in the words of Java, the downward transformation is not supported), thus available as! (Strong turn)
The compiler will also prompt you to use the as! , as! Strong turn if the type does not meet will be an error.
Three, as?
As? Equivalent to the optional type if the conversion fails to return nil.
On the code!
Broadway Swift Learning Summary (i)