Given the following in Swift:
var optionalString: String?
let dict = NSDictionary()
What is the practical difference between the following
They are two different forms of Downcasting in Swift.
(as?), which is know to be the Conditional Form, returns an optional value of the type you are trying to downcast to.
You can use it when you are not sure if the downcast will succeed. This form of the operator will always return an optional value, and the value will be nil if the downcast was not possible. This enables you to check for a successful downcast.
(as!), which is know to be the Forced Form, attempts the downcast and force-unwraps the result as a single compound action.
You should use it ONLY when you are sure that the downcast will always succeed. This form of the operator will trigger a runtime error if you try to downcast to an incorrect class type.
For more details, please check Type Casting section of Apple's documentation.