Post

Replies

Boosts

Views

Activity

NewDocumentButton in DocumentGroupLauchScene crashes for SwiftData Document-Based App
I have a SwiftData document-based app. It is initialized like this: @main struct MyApp: App { @State private var showTemplatePicker = false @State private var documentCreationContinuation: CheckedContinuation<URL?, any Error>? var body: some Scene { DocumentGroup(editing: .myDocument, migrationPlan: MyMigrationPlan.self) { CanvasView() } DocumentGroupLaunchScene(Text("My App")) { NewDocumentButton("New", contentType: .canvasDocument) { try await withCheckedThrowingContinuation { continuation in documentCreationContinuation = continuation showTemplatePicker = true } } .fullScreenCover(isPresented: $showTemplatePicker) { TemplateView(documentCreationContinuation: $documentCreationContinuation) } } background: { Image("BoardVignette") .resizable() } } } extension UTType { static var canvasDocument: UTType { UTType(importedAs: "com.example.MyApp.canvas") } } Pressing the New button crashes with: #0 0x00000001d3a6e12c in (1) suspend resume partial function for closure #1 () async -> () in SwiftUI.IdentifiedDocumentGroupDocumentCreation.createNewDocument(with: SwiftUI.IdentifiedDocumentGroupConfiguration, url: Swift.Optional<Foundation.URL>, newDocumentProvider: Swift.Optional<SwiftUI.AsyncNewDocumentProvider>, _: (Swift.Optional<SwiftUI.PlatformDocument>) -> ()) -> () () All sample code that I've seen uses a FileDocument but SwiftData's setup doesn't have one so it's not completely clear how you should be using NewDocumentButton with a SwiftData file. The crash happens even before my prepareDocumentURL handler is called (I set a breakpoint and it never stops). My hunch is that the crash is because it's not able to match my contentType to a Document. Can anyone at Apple help? I don't think this use-case has been documented well.
2
1
71
May ’25
How do you set UICollectionView context menu to use .compact presentation?
When implementing the collectionView(_, contextMenuConfigurationForItemAt, point) in the UICollectionView delegate, how to specify that the menu should appear in the UIContextMenuInteractionAppearance.compact as the Files app does in iOS 14? And a followup question: how do I display a submenu from said compact menu when using a collection view?
0
0
488
Aug ’20