TEAM LICENSES: Save money and learn new skills through a Hacking with Swift+ team license >>

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

Forums > SwiftUI

@zorn  

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 the init looks something like:

    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:

// 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

2      

Hacking with Swift is sponsored by String Catalog.

SPONSORED Get accurate app localizations in minutes using AI. Choose your languages & receive translations for 40+ markets!

Localize My App

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.