I now have a view where I need to display thousands of results from Core Data and I need to figure out how to handle the delay; either by optimizing the code, adding a ProgressView() or some other option. What is the best way to let the user know something is loading, or better yet, avoid the delay?
When I click on a button, there is an obvious and unwanted delay before it pushes to the new view displaying all the data. I've tried LazyVStack, but since I'm loading by sections, the view jumps around as data is loaded as the user scrolls.
I thought maybe using a technique similar to loading infinite lists, but can't figure out how that would work with a Core Data fetch and the sections/foreaches.
I also thought maybe using a ProgressView() but I can't figure out how to know that the results from the Core Data fetch have fully loaded.
Code snippet below the example (sorry if I missed a } or a )). I have categories of grouped items and want the view to look something like this:
BigView
BigSubView
When I click on a button, there is an obvious and unwanted delay before it pushes to the new view displaying all the data. I've tried LazyVStack, but since I'm loading by sections, the view jumps around as data is loaded as the user scrolls.
I thought maybe using a technique similar to loading infinite lists, but can't figure out how that would work with a Core Data fetch and the sections/foreaches.
I also thought maybe using a ProgressView() but I can't figure out how to know that the results from the Core Data fetch have fully loaded.
Code snippet below the example (sorry if I missed a } or a )). I have categories of grouped items and want the view to look something like this:
Code Block Category 1 Group 1-1 Item 1-1-1 ... Item 1-1-n Group 1-2 Item 1-2-1 ... Item 1-2-n Category 2 Group 2-1 Item 2-1-1 and so on
BigView
Code Block var body: some View { ScrollView{ //categoryList is a [String] of Category Names and each Group has an attribute called CategoryName ForEach(categoryList, id:\.self){category in Section(header: Text(category) ){ VStack{ //Group is an entity in Core Data, and the fetchedEntity with a predicate on CategoryName ForEach(groups){group in BigSubView(group: Group) } } } } }
BigSubView
Code Block @ObservedObject var group: Group var body: some View { Section(header: HStack{ Text(group.wrappedName) }.background(Color(UIColor.systemFill))){ VStack{ //A Group has a one-many relationship with Item entity in Core Data, I convert that to an [Item] ForEach(group.itemsArray, id:\.self){item in Text(item.wrappedName) } } } }