Can anyone help to understand what is causing this warning message on this SampleCode.
- it happens when data in table gets updated
- it happens when I have lot of items in table and search for lets say # 6543 and then clear the search.
"WARNING: Application performed a reentrant operation in its NSTableView delegate. This warning will become an assert in the future."
If there are just few items in table, the warning is not there.
And it started when updated to Xcode Version 14 and upward
import SwiftUI
import Foundation
@main
struct TestProjectSWIFTApp: App {
@StateObject var mydata: MyData = MyData()
var body: some Scene {
WindowGroup {
ContentView()
.environmentObject(mydata)
}
}
}
struct ContentView: View {
@EnvironmentObject var mydata: MyData
var body: some View {
NavigationView{
NavigationLink("TABLE", destination: MyTable())
}
}
}
struct User: Identifiable {
let id: UUID = UUID()
var name: String
var score: Int
}
struct MyTable: View {
@EnvironmentObject var mydata: MyData
@State private var sortOrder = [KeyPathComparator(\User.name)]
@State var searchText: String = ""
var searchResults : [User] {
if searchText.isEmpty {
return mydata.alldata
} else {
return mydata.alldata.filter{$0.name.localizedCaseInsensitiveContains(searchText)}
}
}
var body: some View {
Button("Generate new data", action: {
mydata.updateTable()
})
Table(searchResults, sortOrder: $sortOrder) {
TableColumn("Score"){
Text("\(Double($0.score))")
}
TableColumn("user", value: \.name)
}
.onChange(of: sortOrder) {
mydata.alldata.sort(using: $0)
}
.searchable(text: $searchText)
}
}
@MainActor class MyData : ObservableObject{
@Published var alldata: [User] = []
init(){
self.setData()
}
func setData(){
alldata = [
User(name: "User 1", score: 95),
User(name: "User 2", score: 80),
User(name: "User 3", score: 85)
]
}
func updateTable(){
var newallData: [User] = []
var x = 0
while x < 10000{
newallData.append(User(name: "User #\(x)", score: Int.random(in: 10..<999999)))
x = x + 1
}
alldata = newallData
}
}