UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

SOLVED: iExpense - onDelete not deleting

Forums > 100 Days of SwiftUI

Hi all,

Been trying to figure out why my remove function is not removing from core. The delete function works, when you remove expenses but when you go to add more expenses, the previous delete items come back from the dead like zombies. At first, I thought maybe the UUID is generating different IDs for each item and when I delete one, its removing a copy versus the original. So I wrote a function in my viewmodel to make sure its removing the exact ID but that didnt work either.

It seems that this occured when I started to slit my views up. If anyone can shed some light why its doing this, I would greatly appreciate it.

Github code: https://github.com/EyeOfHorus396/iExpense/tree/main

2      

@Bnerd  

Three changes in your ContentView

@State private var isShowing: Bool = false

    @StateObject var expenses =  Expenses() //Ch1
    @StateObject var bizExpenses = BusinessExpenses() //Ch2

    var body: some View {

        NavigationStack {
            VStack {
                if isShowing {
                    Menu()

                }

                ExpView(expenses: expenses, bizExpenses: bizExpenses) //Ch3

It works for me :)

3      

@Bnerd - you saved my sanity! Thank you!

2      

@Bnerd  

My congrats for your attempt, your layout and the way you structured your code makes mine look like kindergarten :P

3      

I appreciate the compliment but I am still learning, trying to push myself on these projects. :)

2      

BUILD THE ULTIMATE PORTFOLIO APP Most Swift tutorials help you solve one specific problem, but in my Ultimate Portfolio App series I show you how to get all the best practices into a single app: architecture, testing, performance, accessibility, localization, project organization, and so much more, all while building a SwiftUI app that works on iOS, macOS and watchOS.

Get it on Hacking with Swift+

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

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.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.