New SwiftUI FileDocument protocol: How do init a ReadConfiguration during testing?

I recently observed some protocol changes to FileDocument in the Xcode 12 beta 6 release. It was easy enough to get my app working again, but I am having trouble updating my tests.

In my tests I programmatically create instances of my Document to verify it will migrate older file formats properly. With the updated FileDocument protocol I the init looks something like:

Code Block swift
init(configuration: ReadConfiguration) throws {
guard let data = configuration.file.regularFileContents,
let string = String(data: data, encoding: .utf8)
else {
throw CocoaError(.fileReadCorruptFile)
}
text = string
}


How do I initialize a ReadConfiguration in a test?

When I try to do it I get a error:
Code Block
// ERROR: 'PeopleDocument.ReadConfiguration' (aka 'FileDocumentReadConfiguration') cannot be constructed because it has no accessible initializers

More info can be found on this GitHub issue:

https://github.com/zorn/VersionedFilesDemo/issues/1

Replies

Still stuck on this. Any chance a week of beta 6 have helped other people discover the issue?
@zornlabs You mention you were able to get your app working again. How are you doing so? I'm unable to init my FileDocument at all.
@KyleC You can see how I updated my app to use the newest FileDocument APIs on this PR:

https://github.com/zorn/VersionedFilesDemo/pull/2/files#diff-d343a0dee1b2cf89382d8bd5d7abaa73L17