I have this Objective-C Code :
- (IBAction)selectFileButtonAction:(id)sender {
//create open panel...
NSOpenPanel* openPanel = [NSOpenPanel openPanel];
In SwiftUI
struct FileView: View {
var body: some View {
Button("Press Me") {
let openPanel = NSOpenPanel()
openPanel.prompt = "Select File"
openPanel.allowsMultipleSelection = false
openPanel.canChooseDirectories = false
openPanel.canCreateDirectories = false
openPanel.canChooseFiles = true
openPanel.begin { (result) -> Void in
if result.rawValue == NSApplication.ModalResponse.OK.rawValue {
let selectedPath = openPanel.url!.path
print(selectedPath)
}
}
}
}
}