How can I prevent a document-based swiftUI app from saving files?

I implemented the DocumentGroup as follows

Code Block
DocumentGroup(viewing: MyDoc.self) { file in
      ContentView(document: file.$document)  
    }


The documentation says that this should allow viewing, not editing.


Code Block
init(viewing: Document.Type, viewer: (FileDocumentConfiguration<Document>) -> Content)

Creates a document group that is able to view file documents.
Available when Document conforms to FileDocument and Content conforms to View.

However if I press Cmd+S or click File > Save the ability to save documents still appears to be there. How can I prevent this?

I already set "User Selected File" to Read-Only under Signing and Capabilities in Xcode. Have I missed a step somewhere?

I've added a link to a sample project demonstrating the issue. It can open any plain text file with the .txt extension and can save changes to those files.

Sample Project

TBH this seems like a bug that the app does not honour the File Access settings
I submitted this as a bug - https://feedbackassistant.apple.com/feedback/8907308

If anyone thinks it's misconfiguration let me know, thanks
I'm not on BigSur so I can't build your test app on my current machine, but you have declared your app as Editor for the role in you document type declaration: select your project in the navigator, select the target, go to Info tab, under Document Types set role to Viewer (which means your app does not create this type of doc) and try Handler rank to Alternate instead of Default (I think default is Owner if I remember correctly, which is not the case for your app). The type is also declared as Imported which is correct. Try that and see what difference it makes.
Was it a bug later? Feedback Not Found

I had the same problem now.


I submitted this as a bug - https://feedbackassistant.apple.com/feedback/8907308


Feedback Not Found

In Feedback Assistant you can only see bug reports that you filed (1). It’s good that conorg posted their bug number, because it lets Apple folks see the bug and it gives you a concrete handle to the bug if you end up discussing it with Apple folks, but it doesn’t allow you to view it.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

(1) Or your team. See Sharing Feedback with Your Team on Developer Bug Reporting.

I just removed the menu:

import SwiftUI

@main
struct FlowApp: App {
    var body: some Scene {
        DocumentGroup(viewing: FlowDocument.self) { file in
            ContentView(document: file.$document)
        }
        .windowStyle(HiddenTitleBarWindowStyle())
        .commands {
            SidebarCommands()
            CommandGroup(replacing: .saveItem) { }     //// <<<<< HERE
        }
    }
}

Not sure if this is what you are looking for.

Also, added an error:

func fileWrapper(configuration: WriteConfiguration) throws -> FileWrapper {
    throw CocoaError(.fileWriteNoPermission)
}

But, yes, I'm missing that the DocumentGroup does that internally.

How can I prevent a document-based swiftUI app from saving files?
 
 
Q