プロトコルをクラスや構造体、列挙型と同じような方法で定義します。
protocol SomeProtocol {
// プロトコルの定義
}
型の定義の一部として、型の名前の後にコロンで区切ってプロトコルの名前を置くことで、型が特定のプロトコルを採用することを示します。複数のプロトコルをカンマで区切って列挙することができます。
struct SomeStructure: FirstProtocol, AnotherProtocol {
// 構造体の定義
}
クラスにスーパークラスがある場合には、採用するプロトコルの前にスーパークラスの名前をカンマで続けて列挙します。
class SomeClass: SomeSuperclass, FirstProtocol, AnotherProtocol {
// クラスの定義
}
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.