|
So I am using Core data and Swiftui and everything have been working fine but in this one view I have a List, ForEach that is giving not working. So for testing purpose my code currently look like this:
The problem is my List { ForEach, first time I press add button it shows the new why, second time i press the button the whole list goes away, the third time I press the button the list shows again with all 3 items. To test the problem I added that first ForEach part and that shows the correct item at all times, so there is not a problem with the viewmodel or adding the items, the items are added and it is published from the viewmodel since that part is updated. Does anyone have any clue why my List { ForEach only show every other time? |
|
Since the problem lies somewhere in here:
we need to see your |
|
Datamanager fetch
fbhealer fetch
|
|
One or two style things I would mention is that Also why expose a method, even to yourself that takes a NSPredicate as an input paramter? I know the underlying API takes a predicate but from an API point of view NSPredicate is more flexible and Apple have to open the whole database up to muptiple query types, but depending on how many different searches you have to make you may not have that restriction, and could make that cleaner at the callsite i.e.
which takes the search term and some Enum
Then within that function you can build up the predicate from
Back to what is happening here. It might well be in SwiftUI or Core Data, or an intergration between the two. There are two UI views showing the whys, though, the VSTack and the List. Are you saying that both disapper, or one? I also notice that the createWhy also fetches a result and updates the It could also be a threading issue. At least on UIKit you have to be careful about threading and I think that you may be getting into conflict here. So try not calling the (Note: you dont seem to be printing out the newly found whys in |
|
Thanks for all the help, I got tips from stackoverflow that solved this, no clue why it worked... Adding .id(UUID()) to the list and suddenly it started working correctly... Huge thanks to @eoinnorris I will rework some of it :) |
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!
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.