|
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 |
|
SAVE 50% All our books and bundles are half price for Black Friday, so you can take your Swift knowledge further without spending big! Get the Swift Power Pack to build your iOS career faster, get the Swift Platform Pack to builds apps for macOS, watchOS, and beyond, or get the Swift Plus Pack to learn advanced design patterns, testing skills, and more.
This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.
All interactions here are governed by our code of conduct.
Link copied to your pasteboard.