|
I have a main view with a @StateObject
This object has two @Published properties
I then have two views on this main view that use @ObservedObject
Inside one view, it sill display syncProgress messages as they are added to the syncProgress. These are displayed in a scrollview. This works great.
This scroll view uses a child view SyncLogView to display the messages.. it has a lot of code, so I don't want to paste all of it here. This view updates when the syncing is going on. No problem here. The issue is whith my other child view which is in my main view which will display changes to the syncItems array. As items get sync'd both of these arrays are updated. This works in my Child View:
But this doesn't! It will not update the UI
My SyncItemView is the same as the view above:
Why will the ForEach not work and update the items. They do for the other array I am changing and publishing? Any ideas? |
|
@bitco is out of sync
This is a guess.
View FactoryWhat does a I think of If the number of items in this array doesn't change, the parent view will not reinvoke the Maybe you can test this by adding a dashboard just above the
Why does the other ForEach update?But you have another chunk that seems to work. Yikes, why does this code work?
Another guess. The parent View FactoryHere's some other notes on See -> View Factory Keep Coding!Please return here and share what you learned with the rest of us. |
|
Interesting... I think you are correct. I just like the seperation of concearns of that view so I can just work on it in a seperate preview to make it look the way I want. The array is defined at the beginning of the view, only the data changes withing the array. Is there a way that I can get the ForEach to understand that the array data has changed and needs to be drawn again? |
|
I was able to make this work by doing the following. Do you see any issues with what I might be doing?
I am of course doing my ForEach based on the id. From what you pointed out, my id never changed because I am using a class. As a struct it would generate a new id because it is recreated everytime you make a modification to a value inside the struct. So, as a class I just changed the id anytime the syncing was started or completed, which in turn will make the ForEach re-draw that item. This works. The question is, is it safe? |
SPONSORED Still waiting on your CI build? Speed it up ~3x with Blaze - change one line, pay less, keep your existing GitHub workflows. First 25 HWS readers to use code HACKING at checkout get 50% off the first year. Try it now for free!
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.