型キャストは、インスタンスの型をチェックする、あるいはそのインスタンスをクラス階層の異なるスーパークラスやサブクラスとして扱う方法です。

Swift の型キャストは、is および as 演算子で実装します。これらの演算子は、値の型をチェックする、あるいは値を異なる型にキャストするシンプルで表現力のある方法です。

また、Checking for Protocol Conformance で説明されているように、型がプロトコルに準拠しているかをチェックするために型キャストを使用することもできます。


Portions of this page are translations based on work created and shared by Apple and used according to terms described in the Creative Commons Attribution 4.0 International License.