Chris asks for advice:
What am I doing wrong here? ... snip... [app] crashes with an "Index out of range" error
One of the first things that I see is you're not using powerful array features. I've followed the 100 Days of SwiftUI, so am not sure the order of some of your lessons. But is seems you missed a major lesson on filtering arrays. Just a guess, but I think the goal of Project 7 is to apply what you learned about powerful built-in array functions.
Instead, you are writing your own. This is also a good lesson because by writing your own, you've introduced bugs. This is wasteful and annoying. Instead, teach yourself to rely on built-in functions, they are convenient, fast, and bug-free!
See-> Filtering Arrays
Also, when I see code like this:
else {
// Why are you building your own "array transfer" code?
for petition in petitions {
filteredPetitions.append(petition)
print(filteredPetitions.count)
}
}
I think, "Chris is just transferring the contents of one array to another." If so, why not just make an assignment?
// Don't write your own! Just make a copy.
else {
filteredPetitions = petitions // just return ALL the petitions, no filters!
}