The fileOpenDialog function returns an array of optional URLs. What does that function return when you call it? The following line is going to crash if the array is empty:
var csvURLString = fileOpenDialog()[0]?.path
SwiftUI has a fileImporter modifier that shows an Open panel so you can avoid using NSOpenPanel. Searching for swiftui fileimporter in a search engine brings up several articles on using the file importer. If you still want to use NSOpenPanel with SwiftUI, the following article may help you:
https://serialcoder.dev/text-tutorials/macos-tutorials/save-and-open-panels-in-swiftui-based-macos-apps/
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags: