Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | |
| 7 | 8 | 9 | 10 | 11 | 12 | 13 |
| 14 | 15 | 16 | 17 | 18 | 19 | 20 |
| 21 | 22 | 23 | 24 | 25 | 26 | 27 |
| 28 | 29 | 30 | 31 |
Tags
- uiscrollview
- 스위프트
- 애니메이션
- swiftUI
- Xcode
- UITextView
- UICollectionView
- combine
- Clean Code
- Observable
- MVVM
- Protocol
- uitableview
- scrollview
- tableView
- collectionview
- 리펙토링
- ios
- RxCocoa
- ribs
- Human interface guide
- clean architecture
- 클린 코드
- 리팩토링
- map
- swift documentation
- rxswift
- Refactoring
- HIG
- SWIFT
Archives
- Today
- Total
김종권의 iOS 앱 개발 알아가기
[iOS - swift] nested protocol 개념 (#Swift 5.10) 본문
nested protocol
- swift 5.10 아래 버전에서는 아래처럼 protocol을 struct/class/enum/actor/function 하위에 정의가 불가능

- swift 5.10 이전에서 Delegate protocol을 만들려고하면 아래처럼 외부에 Delegate를 정의하고, 안에서도 접근할때 fullName으로 접근해야함
- (TableView안에 protocol 정의가 가능하면 외부에서는 TableView.Delegate로 접근이 가능하고, 내부에서는 단순히Delegate 이름으로만 접근이 가능)
class TableView: UIView {
weak var delegate: TableViewDelegate
}
protocol TableViewDelegate {
}
- swift 5.10부터는 내부에 protocol정의가 가능
- 외부에서는 TableView.Delegate, 내부에서는 단순히 Delegate로 간결하게 접근이 가능
class TableView {
weak var delegate: Delegate?
protocol Delegate { /* ... */ }
}
사용하는쪽)
- 사용하는쪽도 TableView. 네임스페이스로 접근하기 때문에 직관적으로 TableView와 관련된 것이라는 의미 파악도 쉬운 장점
class DelegateConformer: TableView.Delegate {
func tableView(_: TableView, didSelectRowAtIndex: Int) {
// ...
}
}
* 참고
- https://github.com/apple/swift-evolution/blob/main/proposals/0404-nested-protocols.md
'iOS 응용 (swift)' 카테고리의 다른 글
| [iOS - swift] 추상화하기 목차 (0) | 2024.01.28 |
|---|---|
| [iOS - swift] device 분기 방법, 시뮬레이터 분기문 (targetEnvironment, os, arch, swift) (0) | 2024.01.27 |
| [iOS - swift] CustomStringConvertible 개념 (#description, #print 커스텀, #String(describing)) (0) | 2024.01.23 |
| [iOS - swift] ipa 파일 reverse engineering 시작하기 (#ghidra, NSA, National Security Agency) (3) | 2024.01.17 |
| [iOS - swift] Optional의 map, flatMap 함수 (0) | 2024.01.16 |
Comments