I am trying to extract the URL of the document a user has selected in the default "Open" dialogue of my document based macOS application. I understand, a fileWrapper is passed to the init method but is there a way of extracting the path/URL from said wrapper?
Thanks,
Lars
CodePudding user response:
The FileWrapper
has a filename
field, so you'd presumably use that.
CodePudding user response:
The open panel gives you the URL if someone clicks the Open (OK) button. NSOpenPanel
has a urls
property that contains the URLs of the selected files.
SwiftUI file importers give you a URL if the open was successful.
.fileImporter(isPresented: $isImporting, allowedContentTypes:
[.png, .jpeg, .tiff], onCompletion: { result in
switch result {
case .success(let url):
// Use the URL to do something with the file.
case .failure(let error):
print(error.localizedDescription)
}
})