Open / save prompts for macOS and iOS
WizardHelper is a Swift library that provides open and save prompts for macOS and iOS. It uses NSOpenPanel
and NSSavePanel
on macOS, and UIDocumentPickerViewController
on iOS.
You can install WizardHelper using Swift Package Manager. Add the following line to your Package.swift
file:
.package(url: "https://github.com/eonist/WizardHelper.git", .branch: "master")
// macOS: Prompt the user to save a file
WizardHelper.promptSaveFile(fromURL: url, fileName: fileInfo.fileName, view: self)
// macOS: Prompt the user to open a file
WizardHelper.promptOpenFile(view: self)
// iOS: Prompt the user to open a file
WizardHelper.promptOpenFile(from: self) { result in
switch result {
case .success(let urls):
// Do something with the selected URLs
case .failure(let error):
// Handle the error
}
}
// open
WizardHelper.openFile { (url, error) in
if let url = url {
print("Opened file at \(url)")
} else if let error = error {
print("Failed to open file: \(error)")
}
}
// save
let url = URL(string: "https://example.com/myfile.txt")!
WizardHelper.saveFile(fromURL: url, fileName: "SavedFile.txt") { print("File saved") }
- You might need to set
Supports opening documents in place
,Application supports iTunes file sharing
, andSupports Document Browser
toYES
in your app's Info.plist file. - You might need to set
app-sandbox - user selected files - read / write
totrue
. - See this link for more Info.plist gotchas.
- Add github action
- Add tests (UITests) 👈
- Add SwiftUI support 👈
WizardHelper is available under the MIT license. See the LICENSE file for more info.