多くのケースで、型パラメータには Dictionary<Key, Value>
の Key
と Value
や、Array<Element>
の Element
のような記述的な名前を持ち、型パラメータとジェネリック型や関数の間の関係について読み手に伝えます。しかし、意味のある関係が無いときには、前に見た swapTwoValues(_:_:)
関数での T
のように、T
, U
, V
のような一文字を使用して命名するのが慣習です。
NOTE
値でなく型のプレースホルダであることを示すために、常に型パラメータには(
T
や MyTypeParameter
のような)大文字のキャメルケース名を付けます。
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.