Thread 1: EXC_BAD_ACCESS (code=2, address=0x16cd2fff8)

I fill a simple list retiring data from a json file. filtering the record. I can fill correctly the list and I can view the result. of the filtered data.
If I use a button to return in the content view, I receive this error:
Thread 1: EXC_BAD_ACCESS (code=2, address=0x16cd2fff8) if I use the final json file (about 45000 record).
When I use a json file with 1000 item, all is ok.
Help me, please
Can you show your code?
with this code I fill the list

struct RisultatiRicercaNominativo: View {

    @EnvironmentObject var ricerca: Ricerca
    let elettore: Elettore
    var ricercaPrecisa :Array = [String]()

    var ricercaarrey = [Array<Any>]()
    var body: some View {
        VStack {

        navRitorno()

                .background(Color.blue)

List {

                ForEach(elettori) { item in
                        // CASO NOME PIENO E COGNOME PIENO

                        if ricerca.nome != "" && ricerca.cognome != ""  {
                            if String(item.cognome).contains(ricerca.cognome.uppercased())  && String(item.nome).contains(ricerca.nome.uppercased()){

                                ElettoreSingoloView(elettore: item)

                                    .padding(.horizontal, 20)

                            } else {

                                EmptyView()

                            }
                        } //End if

                        // CASO NOME VUOTO E COGNOME PIENO

                        if ricerca.nome == "" && ricerca.cognome != ""  {

                            if String(item.cognome).contains(ricerca.cognome.uppercased())  {
                                ElettoreSingoloView(elettore: item)

                                    .padding(.horizontal, 20)

                            } else {

                                EmptyView()

                            }

                        } //End if

                    } //END LOOP

                } //LIST

            .listStyle(InsetGroupedListStyle())



I can see the list filled in any case.
With this button I return to the content view:



            Button(action: {

                ricerca.cognome = ""

                 ricerca.nome = ""

                ricerca.sezione = ""

                ricerca.indirizzo = ""
ricerca.isResult = false

             //   }

            }, label: {

                Image(systemName: "chevron.left")

                    .font(.title)

                    .foregroundColor(.white)

            })


If the json file contains 1000 record all is ok :(
Thanks for showing the code. But your code lacks many important parts needed to guess what's happening.
It may be just 45000 record is too large, or you may be doing something wrong in the hidden parts of your code.
Is it the real code ?
You have
Code Block
ForEach(elettori)

but the array is not declared in this code. Where is it declared and loaded ?

Can you see if it crashes before 45000 ?
Could you add a print(index) during the loading of json file (there may be an error in the json itself) to see where it crashes ?

If you post more code, please use the formatter tool (<>), to produce something like this:

Code Block
struct RisultatiRicercaNominativo: View {
@EnvironmentObject var ricerca: Ricerca
let elettore: Elettore
var ricercaPrecisa :Array = [String]()
var ricercaarrey = [Array<Any>]()
var body: some View {
VStack {
navRitorno()
.background(Color.blue)
List {
ForEach(elettori) { item in
// CASO NOME PIENO E COGNOME PIENO
if ricerca.nome != "" && ricerca.cognome != "" {
if String(item.cognome).contains(ricerca.cognome.uppercased()) && String(item.nome).contains(ricerca.nome.uppercased()){
ElettoreSingoloView(elettore: item)
.padding(.horizontal, 20)
} else {
EmptyView()
}
} //End if
// CASO NOME VUOTO E COGNOME PIENO
if ricerca.nome == "" && ricerca.cognome != "" {
if String(item.cognome).contains(ricerca.cognome.uppercased()) {
ElettoreSingoloView(elettore: item)
.padding(.horizontal, 20)
} else {
EmptyView()
}
} //End if
} //END LOOP
} //LIST
.listStyle(InsetGroupedListStyle())
Button(action: {
ricerca.cognome = ""
ricerca.nome = ""
ricerca.sezione = ""
ricerca.indirizzo = ""
ricerca.isResult = false
}, label: {
Image(systemName: "chevron.left")
.font(.title)
.foregroundColor(.white)
})
}
}
}

I can view the result's search in any case (also with the json file with 40.000 record). No problem with the array or the json file is correct. After i fill the list, i've the error simply changing the view.
I haven't used this code:

List {
ForEach(listItems, id: \.self) { (item) in
Text(item)
}.onDelete { (indexSet) in
self.listItems.remove(atOffsets: indexSet)

}
}

I'll try tu use this code in bold.
thank you

I can view the result's search in any case (also with the json file with 40.000 record). No problem with the array or the json file is correct.

That does not mean your code there is right.
thank you OOper, i'll follow your suggestions. I'll post more code as soon as possible.
Thread 1: EXC_BAD_ACCESS (code=2, address=0x16cd2fff8)
 
 
Q