For convenience.
The as?
operator is needed in order to provide a downcast that can fail gracefully. The as!
operator is then a short form of writing something like (value as? Type)!
.
You could live without as!
if you just had as?
, but as!
is more convenient than the code I typed above. Prior to Swift 1.2, as!
was as
, which led to confusion with another use of as
. The move to as!
makes its use clear, and is in line with the ? and ! used for optionals.
In Swift, you can't "just return null and that's it" because values don't support nil or null values by default. You need to use optionals to explicitly indicate the potential for an absence of a value, which is a language choice intended to increase safety. With an optional return, you need to extract the value at some point to work with it, thus the need for as!
or a ! when you are certain that the downcast will succeed.