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.
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
I'm trying to create a UISplitViewController in Storyboard and to implement a Sidebar but the leading edge for both the navigation controller and the contained root view controls (ie the Sidebar) seem to have a leading edge margin that is off the left edge fo the screen.
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?