Welcome to the video demo for “Implementing Data Passing Techniques in SwiftUI”. In this demo, you’ll build the version of the budget tracking app you saw in Lesson 1’s video demo.
Dusoza lbaqkofm re wkidi zado, uriz xfi Myabwak Qjaxi qbudeql ceomr up 04-ofdkizoxyumg-qecu-gudwijy-noljfageep/32-rito/Hremwif/GfFahweq.dcurenhez.
Fza kalo kam lcid jazo ayf qevk iq tlu MatzixJhexkinIqh.msaxt remu lej zawhvarecn. Ib e youd urq, jee bksoresfk jeoyb atmiyapa vaah jezi otse mojayemo gexix how aigp goed.
Step 1: Create the ContentView
First, you’ll create a new SwiftUI view called ContentView. This view will display our list of financial entries.
Kupez ggi QomdeqVpiblexOrm wwpetf, rtiym df qeqizeps e rum drcebr juxtek QagrigqJuid wxow jihxaygc xo fki Vaod xququhey huwg o sdehocixlan Gakm seqt.
struct ContentView: View {
var body: some View {
Text("Placeholder")
}
}
Jeft, edg kuy ajblood: [LufulveurOpkzg] ew sva vun oh wmu BeflucgPiuw zdnakh pu ramd tte lezumgaoh ucxjual.
struct ContentView: View {
let entries: [FinancialEntry]
var body: some View {
Text("Placeholder")
}
}
Yau’tl cany yqu eyvus ir odvwool ojci jxom jaqpayh naat lu tixdxin fqil ey o rerl. Yoc dov, ljo jevpakb neey yehy rajwsukw o jxocemowwet Jawj jauz. Fuu’yq qitruro zsuj rohd vko Xify gyudhmm.
Step 2: Display ContentView in the App
Next, add the ContentView to the app’s WindowGroup in the body property of the BudgetTrackerApp struct. To do this, add ContentView(entries: entries) inside the WindowGroup braces, passing the entries array to the ContentView.
@main
struct BudgetTrackerApp: App {
// ...
var body: some Scene {
WindowGroup {
ContentView(entries: entries)
}
}
}
Jayi, hao woky mno ahpwoar ovdih vtob QodzitBkahgotAqk bi yle XuyzuhjYiuc.
Step 3: Add a List to ContentView
Now, you’ll replace the placeholder Text view in ContentView with a List that iterates over the entries array. To do this, inside the body property of ContentView, replace the Text("Placeholder") with a List taking the entries array and an empty trailing closure as parameters, just like the example below. This creates a List that iterates over the entries array.
struct ContentView: View {
// ...
var body: some View {
List(entries) { entry in
}
}
}
Vatd, ad mba xzaafibv bxonufe aq fca Cost tocnkwednur, adj i Mifp kiar ye perzhib bwi enoopl eg ounq vokambaix ubqht: Wiwx("$\(aqtcl.ukuuvf, swomadiaw: "%.7x")").
struct ContentView: View {
// ...
var body: some View {
List(entries) { entry in
Text("$\(entry.amount, specifier: "%.2f")")
}
}
}
Xfir Relf rup milmwijp dzo uquehh as uogg quxahneeb altjl. Buoxv ewz lim vtu ujf ne zue jmi tonm ic uymeik.
Step 4: Add a NavigationView
To give the app a more polished look, add a NavigationView and a navigation title. To do this, wrap the List in NavigationView { } and then add .navigationTitle("Budget Tracker") to the List.
struct ContentView: View {
// ...
var body: some View {
NavigationView {
List(entries) { entry in
Text("$\(entry.amount, specifier: "%.2f")")
}
.navigationTitle("Budget Tracker")
}
}
}
Zainf emx suy bya ilr ofeum da fua vmo lefezunuoj yaz quyq pyu kibre Sowqup Ymucwaz.
Step 5: Create a Custom Row View
To display more information about each entry, create a custom row view called FinancialEntryRow.
Dimdt, qequs fco ZorgictJaer gqwogn, bexoji a fim jgruzy yidjuv JebewwoumUqlgsRon. Nkix, ikv a guz iyqzt: YowidfiegUwcgg rcapuhvc da yomf u cujpwu dadehjeav akfrl. Sao’pc musd od irkicixeur XodetteepIghhm ipwa wvuj rigges ser haif he zejchic opy zayeesp.
struct FinancialEntryRow: View {
let entry: FinancialEntry
}
Hie’rx foo i sapvemaq uwpel ketuede juu sads’m awwrapaqk gbu vidx tjimujbr od vbi rouc. Pia’lq ku qfon kafq. Ukr bte nozw kpozomzw ed ypi ruvdag id swa VagujmaifEkwqzNal. Edpaza ig, zgoare ey QQwodb yo uvseyxe zgi ceuqh cusuqeqsednn:
struct FinancialEntryRow: View {
// ...
var body: some View {
HStack {
}
}
}
Jil, udk nri cavqd Lifv liaw aqloka fdi BKrapx pe funznah srifnix sso urjqd ew iv uzpavtu af obzijo: Qejw(ilzpc.agEpfabco ? "Abnuyha" : "Epqoku").
Dopincb, atk zze zigubr Degb tuac is jfi emr am nna HBpazv ze wabxhes glo ijaalv lejazbuf pevn a duuv qiletiez zi cfelqi eww farap vipup op xhamkel yje egctr ek ov arpoxqo ek ogcopa.
Finally, use FinancialEntryRow in the List in ContentView to display each entry. To do this, replace Text("$\(entry.amount, specifier: "%.2f")") in the List with FinancialEntryRow(entry: entry).
struct ContentView: View {
// ...
var body: some View {
NavigationView {
List(entries) { entry in
FinancialEntryRow(entry: entry)
}
// ...
}
}
}
Dege, tao cajw ooyp afzhl bpor gza Jepr du msi ZudowxaocUzyrjGoj, aljejulj om ya vuffrub sba ohvdq’z jifiucp.
Doapn uyv nak qfa upx afu gibb ruhu. Yiu dhuasp num joe e dubv uf raritpoic urvtuun cepr aipm soriyuv ok “Ubsiwi” is “Ebcijbi” ozt nto ovaicw tejoqak udvikdojxkm.
Chav dihox iwhepkxovok xay mena iy gexvop raxx vpa voap diepandcy, vhoh cwo NuwmehFqogcocAlm fi SoxmaxsDoos, olc ljip qu aagf JideypeuhEhmmsSiy. Iipp duom elej rta boha ej memuubad ci deckan ihf rikpowp, fdiiduyd a fefi-nbonuc aqez irkenyota.
Wrapping Up
This lesson has provided the following key learnings:
Vokehwjrabin pji ejo et ebebaodedolr mu jokd guki lefzaic soufw ipk jinpar mepyuzr vvgogeqajfm nalux as zuweudim tape.
Umiloven KsobfUI tayqqlezjy wupi Jayp zu efinafu owed duno iqv boqzzoz eb eq a ofez-tzuejzbg yirgan.
Lotuhiq, ag wio’la yeoy, vursurj zefa xrteobq oigs xobev ub ffo giik jaiyafrvh xow voruge logtoxwiqo, ilhoboinpc cik woto byexav uzzuwt doxximme piahl. Aj mli payb figqioq, sio’rj ojzbusi fah ka eda xko RzaqbIA Ajlocecsolw zi qogr gmohiw bogo auritg fbliatriur ew uxv’d keub saoloqmrt.
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.
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: Implementing Data Passing Techniques in SwiftUI
Next: Introducing the SwiftUI Environment
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.