0

I'm writing a document based SwiftUI application for macOS. When I choose a file in the file selector, I want to see the fullpath of the file, eg: /Users/me/Downloads/readme.txt

How can I get the fullpath of the FileWrapper in the ReadConfiguration?

struct MyDocument: FileDocument {
    var text: String

    init() {
        text = ""
    }

    static var readableContentTypes: [UTType] { [.myDocument] }

    init(configuration: ReadConfiguration) throws {
        let basename = configuration.file.filename!
        // basename only includes "readme.txt" but I want the full path
    }
    
    func fileWrapper(configuration: WriteConfiguration) throws -> FileWrapper {
        let data = text.data(using: .utf8)!
        return .init(regularFileWithContents: data)
    }
}
mash
  • 4,204
  • 4
  • 32
  • 34

0 Answers0