|
Hello, I've tried day 61 challenge but it's not working as expected, as links are greyed out and not working (and navigation title is not displayed). I don't have any error message. Could somebody help me? Here is my code. Thank you very much.
|
|
Hi there! NavigationLink only works inside NavigationStack or NavigationSplitView so just put your List inside like so:
PS. No need to put it for every view. Only according to your data flow. In this particular case you just create in inside UserListView. |
|
Oh my… such a beginner mistake on a hard project! Thanks! And it's working now… If I may, I don't understand where I was supposed to put |
|
I think you don't really need to use MainActor in this project set up due to workflow established. If we think about how we get data there, we can see that our view receives the data from @FetchRequest
and according to documentation it is already run on the main thread. (see @MainActor?)
so when we use .task{}, what we actually do, we fetch our data from server if our cachedUsers is empty. If it is not empty we go to url, get data, and save it to core data, and then @FetchRequest provides that data to UI. Think of it as a pipeline which updates your cachedUsers as soon as there is new data in managed object context. So my understanding you can avoid using it here as it doesn't involve direct interaction with UI... Basically why we need to use MainActor is to make some piece of code, which usually involves interaction or updating our UI, run on main thread. As another example, if we go to url, get data, and use it for our view, then you will be warned to run it on main thread, as |
|
SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.
Sponsor Hacking with Swift and reach the world's largest Swift community!
You need to create an account or log in to reply.
All interactions here are governed by our code of conduct.
Link copied to your pasteboard.