タイプエイリアスは、既存の型に別の名前を定義することです。typealias キーワードで型の別名(エイリアス)を定義します。

タイプエイリアスは、外部ソースからの固有のデータを扱うときなど、文脈的により適切な名前で既存の型を参照したいときに効果的です。

typealias AudioSample = UInt16

型にエイリアスを定義すれば、オリジナルの名前を使う部分のどこにでも、エイリアスを使用することができるようになります。

var maxAmplitudeFound = AudioSample.min
// maxAmplitudeFound は 0

ここでは、UInt16 のエイリアスとして AudioSample が定義されています。エイリアスなので、AudioSample.minは、実際には UInt16.min のことで、maxAmplitudeFound 変数に 0 の初期値を与えています。


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.