79448364

Date: 2025-02-18 13:10:13
Score: 0.5
Natty:
Report link

I had been following the methodolgy laid out in https://www.merrell.dev/ios-share-extension-with-swiftui-and-swiftdata/ but hadn't followed it exactly. It turns out if I pass the newly constructed container from the ViewController to the SwiftUI view like this:

let contentView = UIHostingController(rootView: ShareView(context: context).modelContainer(modelContainer))

then in the SwiftUI view @Environment(.modelContext) private var modelContext

yields a good ModelContext. I'm scratching my head a little, but it works.

Reasons:
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (0.5):
Posted by: Spiff