인프런 커뮤니티 질문&답변
TextField 에 Binding 으로 연결하면 에러 발생
작성
·
19
0
강의 내용중에
아래 2가지가 가능하다고 했는데
1번
TextField("이메일을 입력해주세요", text: $store.email.sending(\.inputEmail))2번
TextField("이메일을 입력해주세요", text: Binding(get: {
store.email
}, set: { email in
store.send(.inputEmail(email))
}))2번 코드로 작성후 이메일주소를 수정후
저장 하니깐 아래와 같은 에러가 발생했습니다.
A "forEach" at "AppStore/MyPageReducer.swift:96" received an action for a missing element.
Action:
MyPageStackReducer.Action.email(.inputEmail)
This is generally considered an application logic error, and can happen for a few reasons:
A parent reducer removed an element with this ID before this reducer ran. This reducer must run before any other reducer removes an element, which ensures that element reducers can handle their actions while their state is still available.
An in-flight effect emitted this action when state contained no element at this ID. While it may be perfectly reasonable to ignore this action, consider canceling the associated effect before an element is removed, especially if it is a long-living effect.
This action was sent to the store while its state contained no element at this ID. To fix this make sure that actions for this reducer can only be sent from a store when its state contains an element at this id. In SwiftUI applications, use "NavigationStack.init(path:)" with a binding to a store.
확인해 보니 pop시 Binding의 set 이 호출되서
이미 path에 없는 element를 호출하게 되서
해당 에러가 발생한다고 합니다.
그럼 TCA 환경에서는 1번을 꼭 사용해야 하는 건지요 ?
답변 1
0
덤벨로퍼
지식공유자
forEach 스코프 구조에서는 스택 요소를 id로 관리합니다
2번같은 수동바인딩을 사용할시 스택의 id 가 바뀌거나 할 경우 id 불일치로 오류가 발생할수있습니다
1번같은 tca 바인딩을 사용하면 tca 내부에서 동적으로 관리된다 합니다.
꼭 tca 바인딩을 쓰지않아도 정상 동작하는 경우가 있으나 일부 저런 오류가 나타날수 있습니다




