init(configuration:)
Creates a document and initializes it with the contents of a file.
Declaration
init(configuration: Self.ReadConfiguration) throwsParameters
- configuration:
Information about the file that you read document data from.
Discussion
SwiftUI calls this initializer when someone opens a file type that matches one of those that your document type supports. Use the file property of the configuration input to get document’s data. Deserialize the data, and store it in your document’s data structure:
init(configuration: ReadConfiguration) throws {
guard let data = configuration.file.regularFileContents
else { /* Throw an error. */ }
model = try JSONDecoder().decode(Model.self, from: data)
}The above example assumes that you define Model to contain the document’s data, that Model conforms to the Codable protocol, and that you store a model property of that type inside your document.