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

SOLVED: iExpense - Transferring data between views

Forums > 100 Days of SwiftUI

Hi all,

I hope someone can point out what I am doing wrong here. Been working on iExpense and thought to push myself a little further on this project so I tried the whole MVVM model achectecture (not sure if im doing it right) and split the views up for a cleaner code structure. Splitting the views was not an issue, but for some reason I cannot get the main view (ExpView.swift) to update when I delete an expense from BusinessExpenseSheet.swift / PersonalExpense.Sheet.swift.

I added the onDelete directly in the viewModel of the class and on the view itself, so that way there is no two instances of a deleting items that could be conflicting data. Also, added an onChange modifer to ExpView.swift for each Button Label that holds the total value for both personal/business expense. That when a change is detected, to update the view.

Everything works fine, besides the fact when I delete an item from Personal or Business, the ExpView doesn't capture the changes of the deleting items. It only captures the added values as I add more expenses.

I tried to changing it from a @StateObject to a @EnvironmentObject to no avail.

If someone can point me the right direction, I would greatly appreciate it. Beens smashing my head on this for the past few days.

GitHub Repo: https://github.com/EyeOfHorus396/iExpense

2      

I downloaded you app and have not tried any testing but just looking at file in the ExpView , you need to use @ObservedObject as below

@ObservedObject var expenses: Expenses
 @ObservedObject var busExpenses: BusinessExpenses

you will need to provide some valur for preview,

Also transfer the @StateObject from PersonalSheet to some view that is central to app like in appExpenseApp

if all else logic is good will work , good luck

3      

Hacking with Swift is sponsored by RevenueCat

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.

Learn more here

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.