Skip to content

🧙‍♂️Crossplatform-save-file-wizard for iOS and macOS

License

Notifications You must be signed in to change notification settings

eonist/WizardHelper

Repository files navigation

Tests codebeat badge

WizardHelper

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.

Index

Installation

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")

Examples:

// 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
    }
}

Example (hybrid iOS / macOS)

// 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") }

Gotcha iOS

  • You might need to set Supports opening documents in place, Application supports iTunes file sharing, and Supports Document Browser to YES in your app's Info.plist file.
  • You might need to set app-sandbox - user selected files - read / write to true.
  • See this link for more Info.plist gotchas.

Todo:

  • Add github action
  • Add tests (UITests) 👈
  • Add SwiftUI support 👈

License

WizardHelper is available under the MIT license. See the LICENSE file for more info.

About

🧙‍♂️Crossplatform-save-file-wizard for iOS and macOS

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages