|
Really scratching my head with this one and hoping someone can point out where I'm going wrong. I finished up HotProspects, but I wanted to practice adding a couple extra features, like deleting entries. For my array of prospects that I gave the 'List' and for completing challenge #3, I ended up needing two enums and two computed properties, the first 'filteredProspects' to sort between Everyone, Contacted and Uncontacted, and a second one 'sortedProspects' to determine the sorting method based on the status of the '@State var sortByName = true' property. When it came to adding the delete() method, I knew I needed a '@State' wrapper around the array, and I also found that I couldn't do that with a computed property. So my thought went to... can I put the logic inside the second computed property 'sortedProspects' in a method, return a new array that is tracked by a @State variable, give that array to delete() and have it work? The code compiles, but as soon as I delete a row it pops back in. I'm struggling to see how I can make the chain work. You'll see how I'm trying to use getFilteredAndSortedProspects() to take my @State array called prospectsArray, apply the post-filter sorting part of the logic, and give it back, but it's not working as I intend. Writing functions like that is really a stretch for me so I'd greatly appreciate any feedback! Here's my 'ProspectsView'
|
|
Hey jessielinden; I had the same problem - the key to solving it was to realize that the sorted array had different indexes than filteredProspects. I added this function to Prospects class (added it here for proper encapsulation):
Then, in ProspectsView I altered the onDelete call to find the index of the id in filteredProspects array that matched the id in my sroted array. Then I called remove() on Prospects class:
|
SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.
Sponsor Hacking with Swift and reach the world's largest Swift community!
This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.
All interactions here are governed by our code of conduct.
Link copied to your pasteboard.