-
TCA binding 액션 내부 타입 바인딩 @CasePathable개발/Swift 2025. 3. 25. 17:07
Binding
보통 아래와같은 방식으로 바인딩을 만들어 노출 비노출 처리함
→ Binding init 보다 더 짧고 간결하게 구현히 가능
$store.presentActionSheet.sending(\\.presentActionSheet),
근데 만약 Action 타입이 내부 세부 타입으로 나누어져있을 경우에 문제가 생김
enum Action { enum CommunityPostReportAction { case setActiveAlert(CustomAlertPopupType?) case showReportedPostGuide(Bool) } case report(CommunityPostReportAction) }
이런경우 위와 같은 방식으로 바인딩 할수가 없음
$store.showReportedPostGuide.sending(\\CommunityPostDetailReducer.Action.CommunityPostReportAction.showReportedPostGuide $store.showReportedPostGuide.sending(\\.report(.showReportedPostGuide)) Cannot convert value of type 'KeyPath<CommunityPostDetailReducer.Action.CommunityPostReportAction, (Bool) -> CommunityPostDetailReducer.Action.CommunityPostReportAction>' to expected argument type 'KeyPath<Case<CommunityPostDetailReducer.Action>, Case<Bool>>'
액션 타입을 CommunityPostDetailReducer.Action 과 맞추어야함
해결
@CasePathable 을 활용하면 dot binding 이 가능해짐
enum Action { @CasePathable // 매크로 추가 enum CommunityPostReportAction { case setActiveAlert(CustomAlertPopupType?) case showReportedPostGuide(Bool) } case report(CommunityPostReportAction) }
그러면 이런식으로 접근이 가능함
$store.showReportSuccess.sending(\\.reportAction.showReportSuccess)
'개발 > Swift' 카테고리의 다른 글
[SwiftUI] NavigationLink pop push 깜빡이는 문제 (0) 2025.04.08 SwiftUI 커스텀 팝업 노출 방법 fullScreenCover (0) 2025.03.25 [Swift] 페이지처럼 넘어가는 스크롤 레이아웃 (Carousel Effect) (0) 2025.02.26 [Swift] 애니메이션 동작시 터치 이벤트가 동작 안하는 이유 (0) 2025.02.26 SwiftUI + TCA 활용 액션 시트 구현 confirmationDialog (0) 2025.02.07