Why Typecast error occured when using TCA StoreOf?

33 Views Asked by At

I have a problem of type casting Feature in ProfileView. This is a problem code-block.
When I use it, this message is shown:

Failed to produce diagnostic for expression; please submit a bug report (https://swift.org/contributing/#reporting-bugs)

ProfileView.swift:

@Perception.Bindable var store: StoreOf<ProfileFeature>
...

if let additionalOptionFeature = store.scope(state: \.additionalOptionFeature, action: \.additionalOptionFeature) as? StoreOf<AdditionalOptionFeature>  {
    FloatingPlusButtonView(store: additionalOptionFeature)
                    .offset(x: width / 2 - 30 - HORIZONTAL_PADDING, y: height / 3)
}

I use ProfileFeature and ProfileView.

ProfileFeature.swift:

@Reducer
struct ProfileFeature {
    @ObservableState
    struct State: Equatable {
        @Presents var additionalOptionFeature: AdditionalOptionFeature.State?
    }
    enum Action {
        case additionalOptionButtonTapped
        case additionalOptionFeature(PresentationAction<AdditionalOptionFeature.Action>)
    }
}

And also FloatingPlusButtonView and AdditionalOptionFeature.

FloatingPlusButtonView.swift:

struct FloatingPlusButtonView: View {
    @Perception.Bindable var store: StoreOf<AdditionalOptionFeature>
    private let startYPos: CGFloat = 60
    private let VERTICAL_PADDING: CGFloat = (40 + 10)
}
import ComposableArchitecture

enum AdditionalOption: String {
    case edit = "Edit-alt"
    case attachLink = "Attach"
    case addHashTag = "hashtag"
}

@Reducer
struct AdditionalOptionFeature {
    @ObservableState
    struct State: Equatable {
        var isClicked: Bool
        var isAddingAboutMeBtnClicked: Bool
        var isAddingLinkBtnClicked: Bool
        var isAddingHashtagBtnClicked: Bool
    }
    ...
}

I follow the official tutorial of TCA.

In Step2, there is a code like this.

.sheet(
      item: $store.scope(state: \.addContact, action: \.addContact)
    ) { addContactStore in
      NavigationStack {
        AddContactView(store: addContactStore)
      }
    }

So I follow this code using sheet same (but i dont want using sheet) like this.

.sheet(item: $store.scope(state: \.additionalOptionFeature, action: \.additionalOptionFeature)) { additionalOptionFeature in
                            FloatingPlusButtonView(store: additionalOptionFeature)
                                .offset(x: width / 2 - 30 - HORIZONTAL_PADDING, y: height / 3)
                        }

and it works. But after I changed this code using if-let code with type-casting, it does not work.

if let additionalOptionFeature = store.scope(state: \.additionalOptionFeature, action: \.additionalOptionFeature) as? StoreOf<AdditionalOptionFeature>  {
                FloatingPlusButtonView(store: additionalOptionFeature)
                    .offset(x: width / 2 - 30 - HORIZONTAL_PADDING, y: height / 3)
            }

I want this code working properly.

0

There are 0 best solutions below