I have a program that displays data in a table in the main view. It gets this data by running a C API Select statement. On the main view there is also a button which allows me to change the sort order to descending. To do so, this button calls the same function initially called to display data but with a different order by string for the Select statement. Selecting the button causes the data to be displayed in descending order and it is very fast. Unfortunately selecting the button also causes a warning to be displayed in Xcode "Application performed a reentrant operation in its NSTableView delegate". I do not understand what to do to resolve the issue. Any assistance will be appreciated. Below is the Context View and the View Model. The QueryDatabase function called in the view model is just the C api calls including Prepare, Step in a while loop and Finalize. If it would be helpful I can add it.
// Main View:
struct ContentView: View {
@ObservedObject var vm: SQLiteViewModel = SQLiteViewModel()
var body: some View {
if vm.loadingData == true {
ProgressView()
.task {
vm.GetSQLData(fundName: "Fund1", numYears: 1, sortOrder: "main.TimeStamp ASC")
}
} else {
HStack {
Spacer()
.frame(width: 135, height: 200, alignment: .center)
Table(vm.fundData) {
TableColumn("Fund") { record in
Text(record.fundName)
.frame(width: 60, height: 15, alignment: .center)
}
.width(60)
TableColumn("Date") { record in
Text(sqlDateFormatter.string(from: record.timeStamp))
.frame(width: 120, height: 15, alignment: .center)
}
.width(120)
TableColumn("Close") { record in
Text(String(format: "$%.2f", record.close))
.frame(width: 65, height: 15, alignment: .trailing)
}
.width(65)
} // end table
.font(.system(size: 14, weight: .regular, design: .monospaced))
.frame(width: 330, height: 565, alignment: .center)
Spacer()
.frame(width: 30, height: 30, alignment: .center)
VStack {
Button(action: {
vm.GetSQLData(fundName: "Fund1", numYears: 1, sortOrder: "main.TimeStamp DESC")
}) {
Text("Date Descending")
} // end button
.frame(width: 140)
} // end v stack
.font(.system(size: 12, weight: .regular, design: .monospaced))
} // end horizontal stack
.frame(width: 600, height: 600, alignment: .center)
} // end else statement
} // end view
}
// View Model:
class SQLiteViewModel: ObservableObject {
var db: OpaquePointer?
@Published var fundData: [TradingDay] = []
@Published var loadingData: Bool = true
init() {
db = OpenDatabase()
}
func GetSQLData(fundName: String, numYears: Int, sortOrder: String) {
DispatchQueue.main.async {
self.fundData = QueryDatabase(db: self.db, fundName: fundName, numYears: numYears, sortOrder: sortOrder)
self.loadingData = false
}
}
}