Link
Notice
HIT해
[iOS/TCA] @CasePathable 본문
728x90
TCA Reducer 내부에서 열거형을 일치시킬때 자주 사용된다.
enum 타입에서 케이스 매칭을 보다 직관적으로 할 수 있게 도와준다.
또한 상태를 스코프로 다룰 수 있어 오류를 방지할 수 있다.
예시를 보자
enum Action {
case alert(PresentationAction<Alert>)
case alertButtonTapped
case confirmationDialog(PresentationAction<ConfirmationDialog>)
case confirmationDialogButtonTapped
@CasePathable
enum Alert {
case incrementButtonTapped
}
@CasePathable
enum ConfirmationDialog {
case incrementButtonTapped
case decrementButtonTapped
}
}
이렇게 선언해두면 사용시에 어떻게 나오는지 보자.
또는 이렇게 사용할 수도 있다.
case .alert(let alertAction):
switch alertAction {
case .incrementButtonTapped:
// Handle incrementButtonTapped for alert
return .none
}
case .confirmationDialog(let dialogAction):
switch dialogAction {
case .incrementButtonTapped:
// Handle incrementButtonTapped for confirmation dialog
return .none
case .decrementButtonTapped:
// Handle decrementButtonTapped for confirmation dialog
return .none
}
}
}
'Swift > UIKit 개발 노트' 카테고리의 다른 글
[iOS/SwiftUI] TCA NavigationStack 개발하기 (1.12.1) (0) | 2024.09.02 |
---|---|
[iOS/SceneKit] Blender hdri 불러와서 적용하기 (0) | 2024.08.30 |
[iOS/SwiftUI] 스크린샷 감지 TCA (0) | 2024.08.30 |
[iOS/SceneKit] defaultCameraController 알아보기 (0) | 2024.08.29 |
[iOS/Swift] SceneKit Shadow 그림자 적용하기 - 1 (0) | 2024.08.29 |