프로토콜 상속
프로토콜은 하나 이상의 프로토콜을 상속 할 수 있고 상속한 요구사항에 요구사항을 더 추가할 수도 있습니다.
상속하는 방법은 클래스의 상속과 비슷하지만 콤마를 통해 여러개의 상속을 리스트화 할 수 있습니다.
다음은 TextRepresentable 프로토콜을 상속하는 프로토콜
PrettyTextRepresentable 프로토콜을 채택하려면 TextRepresentable 프로토콜과 PrettyTextRepresentable 프로토콜의 요구조건을 모두 충족해야 합니다.
확장을 통해 SnakesAndLadders에 PrettyTextRepresentable 프로토콜을 채택
PrettyTextRepresentable 프로토콜을 준수하면 TextRepresentable 프로토콜도 준수하기 때문에 textualDescription 프로퍼티에 접근해서 문자를 출력합니다.
prettyTextualDescription 프로퍼티는 모든 SnakesAndLadders 인스턴스의 설명을 출력하는데 사용할 수 있습니다.
'Swift > 꼬꼬무' 카테고리의 다른 글
Protocol Composition (프로토콜 혼합) (0) | 2023.07.05 |
---|---|
Class-Only Protocol (0) | 2023.07.04 |
Collections of Protocol Types (0) | 2023.07.04 |
Adopting a Protocol Using a Synthesized Implementation (0) | 2023.06.30 |
Protocol 확장을 통한 프로토콜 준수 (0) | 2023.06.23 |