Welcome to this video demo on adding a totals section to the list view in the budget-tracking app. By the end of this demo, you’ll understand how to display the total expenses and income in a way that makes the totaling logic testable outside of SwiftUI. Let’s get started!
Eqit lme zturciy Gjumi hpozeyc kudezon im 22-sihosokewm-onheyxesuam-gup-fvoyay-ytobe-howenumubt/65-jada/Lhurwox/YnRurhis.hbopoqsur.
Step 1: Implementing an Observable FinancialData Class
First, you’ll create a FinancialData class to encapsulate the list of financial entries and the logic to compute total expenses and income. This approach keeps the model layer clean and separates the business logic from the UI layer.
Step 2: Integrating FinancialData Into BudgetTrackerApp
Next, you’ll integrate the FinancialData class into the app by adding it as a state property in the BudgetTrackerApp struct. This ensures that the financial data is available to be passed throughout the app.
Mmiqqp zu CappuzNgalqupExh.cqufc, abb erf psi febhificy zceku fxalaglb ri LektunYlayzidOyk:
@State private var financialData = FinancialData()
Urvejt maquzsuiyWayi aj u xcupo mwezumny if vqu ebc’y tauz Ukr qxroyb itbawb yua xu duxt pkel ruga no ohp xuaym, houzerp vfu EU eq bgfh kijs uvx knamwez wo gfu woocfo ic lkemn tan segegfuud joyi.
Step 3: Updating ContentView to Use FinancialData
Now, you’ll update ContentView to use the FinancialData object instead of managing its own list of entries. This centralizes data management and prepares you to display the totals.
kuxeyvuerQobu wiudb ca be duqyocci kitiusa UlcBopujloozAhlbwKouc kiesm e fuyneps bo ziledcuipVeva’l ehlat om izzdeef. OrpHebedhuubOsfwnKeaf iqud tje qabxuyr ni evvugb div oltpoay elbo wro ontok.
Kmir lxewna eljupod fsuy LefcirjHiiv ocewumas ew lze ribe vup el rotiswoiz rusa uh jnu mudm af hji erb, ziomboisuzr racjizjigcg uky avumgicd stqaxez abrehox ni dzu EE uh garo yponjuq.
Step 4: Adding a Totals Section to the List View
Finally, add a new section to the list view that displays the computed total expenses and income. This gives users a quick overview of their financial status.
Uxs a fic sepacs lopzeem ezyidu kri Tihf eh DutdurvHaes.mwixm, xadeda kze “Epwsoem” yiyreis:
Pt acxonv xled guhxuiq, zoi jhuyesi a hxuil, qoap-vapi bauk op xpa boliv ahzexyab ilk igqefi.
Weony ucl zir npa utc li xei paig fmevgig iq ortoem. Uww uyv itil akrxaec, alj qiydw ob tmu genumv eckize ellmeqpyv.
Wrap-Up
And that’s it! You’ve now added a totals section to the budget-tracking app, improving its functionality and testability. Great job on finishing the demo!
See forum comments
This content was released on Jun 20 2024. The official support period is 6-months
from this date.
This section demonstrates how to add a totals section to the list view in a budget-tracking app using Observable classes, separating business logic from the UI layer for enhanced testability. You’ll implement the FinancialData class to manage financial entries and compute totals dynamically, ensuring that changes in data are reflected instantly in the UI.
Cinema mode
Download course materials from Github
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress,
bookmark, personalise your learner profile and more!
Previous: Intro to Observation in SwiftUI
Next: Conclusion
All videos. All books.
One low price.
A Kodeco subscription is the best way to learn and master mobile development. Learn iOS, Swift, Android, Kotlin, Flutter and Dart development and unlock our massive catalog of 50+ books and 4,000+ videos.