728x90
특정 class 상속받아야만 protocol을 채택하도록 제약 걸기
- protocol을 정의할 때, 해당 protocol을 특정 class를 상속받는 class에서만 채택하도록 제약을 걸고 싶을 때 활용할 수 있는 방법
- 아래 2가지 문법으로 정의가능
- 둘 다 같은 의미와 효과를 가진다.
1. where 절 활용
protocol BaseProtocol where Self: BaseObject {
}
2. 상속 문법 활용
protocol BaseProtocol: BaseObject {
}
728x90
'Swift' 카테고리의 다른 글
[Swift] Swift Object Lifetime (0) | 2022.08.26 |
---|---|
[Swift] Weak vs Unowned Reference (0) | 2022.08.20 |
[Swift] Method Swizzling (0) | 2022.07.09 |
[Swift] 프로토콜 지향 프로그래밍 (Protocol Oriented Program) (0) | 2022.06.19 |
[Swift] 왜 struct에선 mutating을 사용해야하는가? (0) | 2022.06.19 |
댓글