I have a SwiftUI Mac app I am writing... it starts out by calling a func (fileOpenDialog) that calls NSOpenPanel.runModal()...
The NSOpenPanel shows and lets me choose a file... but then crashes the app on Open.
If I don't use NSOpenPanel and just hardcode a file path, everything works fine.
import SwiftUI
struct DialogsTestView: View {
var csvURLString = fileOpenDialog()[0]?.path
// var csvURLString = "/Users/tj4shee/track.csv"
func fileOpenDialog() -> [URL?]
{
let openPanel = NSOpenPanel()
openPanel.title = "Choose csv file"
openPanel.message = "Choose the csv file you want to convert to JSON"
openPanel.showsResizeIndicator = false
openPanel.allowedContentTypes = [UTType.delimitedText]
openPanel.showsHiddenFiles = false
openPanel.canChooseFiles = true
openPanel.canChooseDirectories = false
openPanel.allowsMultipleSelection = false
let results = openPanel.runModal()
return results == .OK ? openPanel.urls : []
}
Thanks for any help, TJ