Is it possible to create SwiftData Document-based apps in App Playgrounds (or Swift Packages, since App Playgrounds are a special type of packages)?
As explained in wwdc2023-10154, to create a document-based app you are required to provide an UTType
that conforms to com.apple.package
. This requires your file type to be declared and exported in the Info.plist
file of an Xcode project, but App Playgrounds don't have them.
Providing .package
as a UTType seems to partially work:
import SwiftUI
import SwiftData
@main
struct SwiftDataFlashCardSample: App {
var body: some Scene {
#if os(iOS) || os(macOS)
DocumentGroup(editing: Card.self, contentType: .package) {
ContentView()
}
#else
WindowGroup {
ContentView()
}
.modelContainer(for: Card.self)
#endif
}
}
This way I am able to run the app, create and edit new document, and save it on disk. However, opening it again does not work (you cannot select it since it is a folder without a defined package type).
Is there any workaround to this?
I guess I could drop support for multiple documents entirely if this is not possible (I don't think this would affect my submission), but I would just like to check if there is any way to do this first.