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

fileWrapper - anyway to conditionally (or totally) disable file saving / overwriting?

Forums > macOS

I am building a document based SwiftUI macOS app and I can't find a way to turn this off. I don't ever want to edit or save over the original file (and I don't wan't to duplicated the original either).

I've tried a bunch of hints from others and none work or are hacks that only half work

I have tried to set the app as only 'viewing' mode as per Apple documentation: DocumentGroup(viewing:

somewhere suggested that this might work as set via delegate (doesn't do anything - haven't tried a negative delay or a million seconds yet) NSDocumentController.shared.autosavingDelay = 0

In fileWrapper, I can throw a random error but this still gets called (just wont overwrite file since not returning new data -- also it presents messsaging to the user of error - if I could throw some other error silently, might be OK) throw CocoaError(.fileWriteNoPermission)

The whole point of the app if to safely crop/edit/greyscale JPEGs without any image re-sampling (it is a front end to JPEGTRAN command line). But it defeats the purpose to overwrite the original file.

Would hate to have to re-write as a non-document based app.


Found a workable solution – I think ( requires using Document as a class vs a struct )--


Use documents as class vs.[valve-cover-gasket]


Hacking with Swift is sponsored by Superwall.

SPONSORED Superwall lets you build & test paywalls without shipping updates. Run experiments, offer sales, segment users, update locked features and more at the click of button. Best part? It's FREE for up to 250 conversions / mo and the Superwall team builds out 100% custom paywalls – free of charge.

Learn More

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

Reply to this topic…

You need to create an account or log in to reply.

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.