UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

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.

3      

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

https://stackoverflow.com/questions/44161308/prevent-nsdocuments-auto-saving-while-its-content-is-editing

3      

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

3      

TAKE YOUR SKILLS TO THE NEXT LEVEL If you like Hacking with Swift, you'll love Hacking with Swift+ – it's my premium service where you can learn advanced Swift and SwiftUI, functional programming, algorithms, and more. Plus it comes with stacks of benefits, including monthly live streams, downloadable projects, a 20% discount on all books, and free gifts!

Find out 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.