Skip to content

Instantly share code, notes, and snippets.

@delasign
Created October 25, 2024 17:49
Show Gist options
  • Select an option

  • Save delasign/5d88ca97de29ed04140e9c6719f24279 to your computer and use it in GitHub Desktop.

Select an option

Save delasign/5d88ca97de29ed04140e9c6719f24279 to your computer and use it in GitHub Desktop.
Sample get file or folder url Swift function
import Foundation
@MainActor
private func getFolderURL(title: String, message: String, canChooseFiles: Bool, canChooseDirectories: Bool, allowsMultipleSelection: Bool) async -> URL? {
let panel = NSOpenPanel()
panel.title = title
panel.message = message
panel.canChooseFiles = canChooseFiles
panel.canChooseDirectories = canChooseDirectories
panel.allowsMultipleSelection = allowsMultipleSelection
switch panel.runModal() {
case .OK:
return panel.url
default:
return nil
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment