Please help me understanding how to setup a basic navigation in a TCA app #2707
-
Hi everyone! I'm trying to write a very simple project using SwiftUI and ComposableArchitecture, and handling a basic navigation. Here is the idea: The user lands on a MainView, which initially displays a LoadingView. I mock an API call, which lasts 1 second, then to display a MyNavigationView which I expect to contain a NavigationStackStore. Ultimately, there is a toolbar with a button to lead to a ReadOnlyView. Here is my code :
Now I have an issue: I get a very generic and random compiler error on the body declaration of MyNavigationView:
More generally, I don't really understand how to do this in a simple way. Could you help me understanding what am I doing wrong? Thank you very much! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
Hi @JohnRoxMySox23, there are a few things wrong with this code, and I would suggest reading the docs and tutorials to understand how to use these APIs. First of all, anytime Swift produces a bad compiler error you should comment out things in the view until it either compiles or produces a better message. And sometimes you need to break things apart into multiple statements to help out Swift. If you do this in your view you will get the true error:
The And you would have seen this problem earlier if you had integrated the .forEach(\.path, action: \.path) {
Path()
} That does not compile and shows that the domains do not match. You need to update your case path(StackAction<Path.State, Path.Action>) That causes a few other errors that are up to you to figure out the best way to fix. And something else that caught my eye in this code was this effect: return .run { send in
DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) {
send(.dataFetched)
}
} This is unfortunately not correct. The It is better to use the tools of Swift concurrency for this: return .run { send in
try await Task.sleep(for: .seconds(1))
await send(.dataFetched)
}
} Hope this helps. |
Beta Was this translation helpful? Give feedback.
Hi @JohnRoxMySox23, there are a few things wrong with this code, and I would suggest reading the docs and tutorials to understand how to use these APIs.
First of all, anytime Swift produces a bad compiler error you should comment out things in the view until it either compiles or produces a better message. And sometimes you need to break things apart into multiple statements to help out Swift. If you do this in your view you will get the true error: