When you create a document-based SwiftUI project, the document struct contains the following initializer:
init(configuration: ReadConfiguration) throws {
// Code to open an existing document
}
In the initial text editor project that Xcode supplies, you don't have to supply the configuration argument when calling the document's initializer in the App file.
var body: some Scene {
DocumentGroup(newDocument: Document()) { file in
ContentView(document: file.$document)
}
}
In my project the document contains an array of another struct and saves the document in a file package. Now the compiler complains that I'm missing the configuration argument in the call to the document's initializer.
If I supply a FileDocumentReadConfiguration object as the configuration argument,
DocumentGroup(newDocument: Document(configuration: FileDocumentReadConfiguration())) { file in
ContentView(document: file.$document)
}
The compiler provides the following error message:
FileDocumentReadConfiguration cannot be constructed because it has no accessible initializers
The information on FileDocumentReadConfiguration in Apple's documentation has nothing on initializers. Searching for FileDocumentReadConfiguration on Google yields only Apple's documentation and an unanswered question on the Hacking with Swift forums. No one has asked a question about this on Stack Overflow.
How do I supply a FileDocumentReadConfiguration object to the document's initializer or how can I avoid having to supply a configuration argument like the default project does?