-1

I have a parent view which does a @SectionedFetchRequest and passes the SectionedFetchResults to a child view. Everything works, and the child view is able to parse through the SectionedFetchResults. However, I can't figure out how to set up the data so that the child's Previews struct will work. What's the proper way to set up some constant data in Previews struct so that I can instantiate the child view and pass in SectionedFetchResults?

See this similar question for a FetchedResults: Passing Core Data FetchedResults for previews in SwiftUI

alpennec
  • 1,864
  • 3
  • 18
  • 25

1 Answers1

0

Use your PersistentController.preview.container.viewContext and preview the View with the @SectionedFetchRequest.

malhal
  • 26,330
  • 7
  • 115
  • 133
  • I want an approach without Core Data for the Views. Something like what is described in this WWDC video where rich models are not used in the Views: Structure your app for SwiftUI previews (https://developer.apple.com/videos/play/wwdc2020/10149). – alpennec Apr 20 '23 at 04:05
  • I was actually going to suggest that but your requirement was to pass the rich models in. – malhal Apr 20 '23 at 08:36