I have no idea how to do it: on MacOS, in Document.init(configuration: ReadConfiguration) I decode file, and restore objects from data, which in some cases could take a long time. Document isn't fully inited, so I have no access to it. But would like to have a progress bar on screen (easier to wait for done, for now). I know size, progress value, but no idea how to make view from object during init.
I know, this question may be very stupid.
init(configuration: ReadConfiguration) throws {
guard let data = configuration.file.regularFileContents
else {
throw CocoaError(.fileReadCorruptFile)
}
let decoder = JSONDecoder()
let flat = try decoder.decode(FlatDoc.self, from: data)
print ("reverting \(flat.objects.count) objects...")
///This takes time, a lot of time, need progress bar
///Total is `flat.objects.count`, current is `objects.count`
/// `Show me a way to the (next) progress bar!`
revertObjects(from: flat.objects)
print ("...done")
}
update: I defined var flatObjects in Document, and I can convert in .onAppear.
struct TestApp: App {
@State var isLoading = false
...
ContentView(document: file.$document)
.onAppear {
isLoading = true
Task {file.document.revertObjects()}
isLoading = false
}
if isLoading {
ProgressView()
}
...
}
But progress bar never shows, only rainbow ball