Repository Public License
1import AppKit2import UniformTypeIdentifiers34/// The real Open and Save panels. Apps only ever see a file the user picked (spec §12).5@MainActor6public final class AppKitDialogs: FileDialogs {7 public init() {}89 public func chooseFileToOpen(allowedExtensions: [String]) -> URL? {10 let panel = NSOpenPanel()11 panel.canChooseFiles = true12 panel.canChooseDirectories = false13 panel.allowsMultipleSelection = false14 let types = allowedExtensions.compactMap { UTType(filenameExtension: $0) }15 if !types.isEmpty { panel.allowedContentTypes = types }16 return panel.runModal() == .OK ? panel.url : nil17 }1819 public func chooseFileToSave(suggestedName: String) -> URL? {20 let panel = NSSavePanel()21 panel.nameFieldStringValue = suggestedName22 panel.canCreateDirectories = true23 return panel.runModal() == .OK ? panel.url : nil24 }25}26