BLACK FRIDAY SALE: Save 50% on all my Swift books and bundles! >>

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]


Save 50% in my Black Friday sale.

SAVE 50% To celebrate Black Friday, all our books and bundles are half price, so you can take your Swift knowledge further without spending big! Get the Swift Power Pack to build your iOS career faster, get the Swift Platform Pack to builds apps for macOS, watchOS, and beyond, or get the Swift Plus Pack to learn advanced design patterns, testing skills, and more.

Save 50% on all our books and bundles!

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.