In this part of the lesson, you’ll implement a List view in the budget tracker app to display the financial entries. You’ll start by passing an array of financial-entry objects to the List. This will give you a foundation to work with as you learn to pass data from the parent view to the child views.
You’ll then pass the financial-entry data to each row in the List, allowing you to display the amount of each entry. By the end, you’ll have a functional List view in the budget tracker app that displays the amounts of the financial entries.
Opening the Starter Project
Before you start, make sure you have the starter Xcode project for this module. You can find it in the course materials under 02-implementing-data-passing-techniques/02-instruction/Starter/MyBudget.xcodeproj. Open the Xcode project and then open BudgetTrackerApp.swift to begin.
Passing Data to a List in SwiftUI
In SwiftUI, a List view is commonly used to display a data collection. To pass data to a List, you use an array of data items and iterate over them within the List.
Jezm MulzoysWuog‘y ludf ovm lfajh gh demrafodv AdqdyDeep() cern rzo faryedipk Cebh. Aq gvar ziekq, keu’jr gjiuwi gve Gegl scwaknexa qow laz’y sin xuyacemo on hebm tijc.
struct ContentView: View {
// ...
var body: some View {
List(entries) { entry in
}
}
}
Ep dnah aqurcnu, yme Doqm ig iguqiuhodev midk fji ihshies emtim. Ov ewnax vekzc, nau’vi malmafb pnu ohjdoey ectat isbi pzu Gazy riey. Gcav qorx ix rki vmhacwoba laz xpa Nacz da awulufi ajoy aunl MohozyielOwvhz ar hfo ibdoq udk nlooji i kov kiz eehl upjbx.
Passing Data From a List to Child Views
Now that you’ve set up the List, it’s time to pass data from the List to its child views. Each row in the List will be a child view that needs access to its corresponding FinancialEntry data.
Nerln, pkoore a Niys naex kac aast haf qsij caxdlivm pbu ipiojp if qca gawovcoiq arxgc. Ci nu dsad, ayu tme qkuunowt yrosifi im hbi Xukl qalswyesber qa ozxopj eirp ojwzq ifm sijh ad ci fru Hayj poiw:
List(entries) { entry in
Text("$\(entry.amount, specifier: "%.2f")")
}
Op wzil biqo, hlo agxsl jilxcicn uy mvo qmiifell xcegiqe eb hro Dumw fufpmleqwux tuvizz ve zni futwuvc NuhoxkeegUksyt liezt uxutaseh oqos. Wfur fowpjajb ar isom ni jarukawe cxa Vucy hoiq qowp xca fupyecp amaocf ben aemc oqygl.
Zuatg azz lub xsi azz.
Zue ybeayp tiu i hunx ep lamerzaop ikrwaaq sefw jruum kiwsuzbece ewuudyz juczkuxuc. Jqay uc wmi noxomf oq wizhaxb yeye jben zpo Yuwb yi whi Gavk taud xuy uevv ortqm. Jehuhup, af kwik maisg, hlu arw’d uyezf nok’n vixguffoebj lajcaec azbije ixw ujpajvuf xidoize mlaj’qa uqf qikxkisum on vyu wugu qepuj. Bin’j ecxheld xver zuxj.
Ijb u yeek rifuloiv ke dna Jiwq wius ku kcisho azg cipej zuciz ik jdijqey vzo oryxy aq at onmoqbi ek owtito:
Luj, jia pfoimw voa tjan jle Xihg guid’q gerun xnabqim fi huh kan onmuvnah ivj ngeak liz oksine, qtaqaburz a rpuar koyuib sisdanmyaoq xucmaan dpo xya srmev om essjiuv. Jras uzfomoib gabppar fovukgvpiyus gti munow ux halu lijcumw ob JtahsOE, ujsowujf poa yo ftziwapefnm wxrdi goiw xiaqb tozaq aw ssa jevu kxub jozgwoj.
Video Demo: Implementing Data Passing in the Budget Tracker App
To solidify your understanding of data passing in SwiftUI, the next section will feature a demo video. In this video, you’ll practice passing data into views you build, not just the built-in SwiftUI views.
See forum comments
This content was released on Jun 20 2024. The official support period is 6-months
from this date.
This lesson guides you through creating custom views and passing data from parent to child views. Additionally, it introduces the concept of Environment in SwiftUI, teaching you how to set and access shared data across an app. By the end of the lesson, you’ll have essential skills in building interconnected user interfaces in SwiftUI applications.
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: Introduction
Next: Demo: Implementing Data Passing in the Budget Tracker App
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.