|
Hello there! I have just completed the challenges for project 7, but I'd like to get a few comments. I'm most definitely sure that they could be solved more easily, but I quite can't put my finger on it. Specifically, I had some problems with the deletion from multiple List sections: I created two sections for the personal and business expenses, filtering the When deleting, it appears to me that SwiftUI calls my What I thought of is "offsetting the offsets", so to speak: I order the array of expenses by type (personal first, business second), so that I know how many personal expenses I have to skip to delete a business one. I admit I didn't test it extensively, it seems to work, but I'm quite sure there would be a better way to solve this. I don't particularly like reassigning the whole array every time I remove something, or having two different functions that perform basically the same task. I attach the code, thanks in advance for the suggestions!
|
|
Hi, I think the problem is when you filter it returns a new array of items, so you're basically dealing with 3 different arrays; What worked for me was using a conditional after the ForEach, wrapping the HStack and it's content inside it; One for Personal and one for Business.
That way you could use just 1 removeItems |
|
hi, the problem is basically that your function
so you need to identify the expenses to be deleted with respect to their indices in this filtered list, and remove these from the base something like this should work
the same goes for hope that helps, DMG |
|
Thanks for the answers! @Hectorcrdna, your solution made very sense to me, but apparently it does not compile. My guess is that it is not able to understand when the iteration of the ForEach will return something (ie, to tell in advance when an expense is personal or business). @delawaremathguy, thanks very much, it was evident yet I couldn't see it, of course the problem was operating on three different arrays. Thanks again! |
SAVE 50% All our books and bundles are half price for Black Friday, so you can take your Swift knowledge further without spending big! Get the Swift Power Pack to build your iOS career faster, get the Swift Platform Pack to builds apps for macOS, watchOS, and beyond, or get the Swift Plus Pack to learn advanced design patterns, testing skills, and more.
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.