FileDocument SwiftUI


  • File Type
  • Auto Save
  • Multiple Documents
  • Get File
  • Incremental Save
  • Sandbox


  • How to set file type and extension? (Support 2 extensions in parallel, then rename. Where located?)
  • How often save? (Save every key stroke, or buffer update or write? Log setter and log write. See which.)
  • How to handle multiple documents? How can app level toolbar and menu commands access current document? FocusedSceneValue.
  • How to get file? File is available at DocumentGroup scene level, not FileDocument document level.
  • How to implement incremental save? Folder file wrapper? Need delta?
  • Sandbox? New document move write restricted by sandbox.


  • The document project template uses boilerplate configuration and code.

File Type

  1. Target Info (per target) has document type com.example.plain-text, and imported type identifier com.example.plain-text, conforms to public.plain-text, extensions exampletext.
  2. Document project template extends UTType with exampleText, imported as “com.example.plain-text”.
  3. Document declares readable content types [.exampleText].
  • Writes .txt extension, not .exampletext.
  • Opens both .txt and .exampletext.
  • Filer opens both .txt and .exampletext in TextEdit, not new app. (With handler rank default. Different is change handler rank to owner?)


  • Rename-move causes sandbox error? What? Can create and write there. Just not move?

Auto Save

  • Add support statements to both set and write. (Add calculated value with setter.)

Auto-Save Cases

  • New Untitled document. Multiple sets consolidated into one write. Delay on order of 10s, or longer (15s). Sometimes delay until close.
  • Saved Untitled document (Gets saved as Untitled.)
  • Save Named document
  • Open Named document. Delay ~15s. Sometimes delay until close. (Set 144…)