プロトコル
目次>
文法
protocol InheritingProtocol: SomeProtocol, AnotherProtocol { //プロトコル定義 }
protocol PrettyTextRepresentable: TextRepresentable { func asPrettyText() -> String }
必要とされるプロパティ
必要とされるメソッド
タイププロトコル
デリゲーション
エクステンションで適合プロトコルを追加する
conformance(適合)
エクステンションでプロトコルアダプションを決定する
プロトコルタイプのコレクション
プロトコルの継承
エクステンション
extension SnakesAndLadders: PrettyTextRepresentable { func asPrettyText() -> String { var output = asText() + ":\n" for index in 1...finalSquare { switch board[index] { case let ladder where ladder > 0: output += "▲ " case let snake where snake < 0: output += "▼ " default: output += "○ " } } return output } }