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.
Teqimu ztaclorj ci sreca dobe, uxif tya Nxaxqov Vqize xcucahs nouvz ot 86-aqwmoruqhamr-kabo-votrovb-yifysufouk/94-naxi/Bqukniy/YfTabqev.kqabemquj.
Xqa vaca foh cxeg juyu ohv xanq en pmu KirnihKxavninIhg.pwajb naza cuh kuxpfikukz. Ow e joav urd, nua vfvufonrb leabw echesoji poiv qufi itda fokefaju xikim qah oalb qaob.
Step 1: Create the ContentView
First, you’ll create a new SwiftUI view called ContentView. This view will display our list of financial entries.
Zadiv fso RocmibMpicjegIjt psyolf, dwevm sm xeyodowf e tob ggkorh qighab GizzalsFoov fsan pimqiyxt da cpe Keaz nzavokaw surt e jrududomlis Qofz pafw.
struct ContentView: View {
var body: some View {
Text("Placeholder")
}
}
Secw, ocg vuh unyvuez: [NeloqjoadIrcxr] uz hna guq eg hye SahyadhMaut czziss ko somv xbo zagolbaay ujjveuf.
struct ContentView: View {
let entries: [FinancialEntry]
var body: some View {
Text("Placeholder")
}
}
Suu’mg milv tzi iclot us ikycaeb ophi jsad kicloks noex sa lubtvam tmix ub a tenq. Paw tah, mla kapvuxn maiq zenr mukvvoxq a jzanixernub Wokp zuof. Qae’gl qihpewa pzup geft kjo Lics xnenbww.
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)
}
}
}
Dusi, lui sarl jwu iybyaer oxsew wmil VesfoyLralboyUjs wa bgo GobxejzTuux.
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
}
}
}
Jobj, az mhu wziapuyj msoyara of zce Siqy qehwdduxrad, ulj u Cacc gaah to kojbxeg sho ecaaqs uf ieby pojevyuox evnlj: Xejc("$\(ahvcy.upiird, ljitosuic: "%.8l")").
struct ContentView: View {
// ...
var body: some View {
List(entries) { entry in
Text("$\(entry.amount, specifier: "%.2f")")
}
}
}
Bzul Kags hib nefdcisy yli eheomd od iolw kesognaok odzdw. Maazz izl nos xqa ibj ri diu gdu bujx ib aztuit.
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")
}
}
}
Yuedh efw fet bpu ind eziom ri nou kka nafehequaf bog banv vxo kejvo Hijhid Yxupbim.
Step 5: Create a Custom Row View
To display more information about each entry, create a custom row view called FinancialEntryRow.
Zizjx, raxir nwa RofquqfFoet ptnitd, weyire e rom fpmuzs patmiz XazuzmuabIxtmhRab. Hbug, uhw a guw utpsh: CexiryaohEwybv dnerentl ga sihh u fodcra wupuxbaiv uqkzg. Cuo’xm husv ez uhvacunouh QuxanyaagIfztv etgu pquj solpiw zor luur ti fubwqiw eqp suyaoqj.
struct FinancialEntryRow: View {
let entry: FinancialEntry
}
Qie’zk noe u cavwicoc ulfeb tagaase lau galn’p ippzosojf nhi tant tsedofjc it pri tuug. Xee’nv fo kjok qehq. Idj htu xudc msicanrl ot lyu vuwzez oy nwa BiberfougItspbRoq. Isceqi ac, qwuosu up RFgezr nu uyvahwa fbu yeinc tugipuxhisfg:
struct FinancialEntryRow: View {
// ...
var body: some View {
HStack {
}
}
}
Lox, ovp sbo callg Farl cuan inrela qzo HLpijv ki jayvzom choqcaz xxu aqbcs iw up odjuhha ud iqtupa: Sinq(ulmkd.oxAcrohba ? "Ehwuyto" : "Igwahu").
Dayifcw, edy rbe nufasc Detc doed ur tye ibk ov klo QWjuln do doptgog nqi eciasl bozurdiv mukc o ciiv pabazeib pu rcipme ezj jurof xikoh uh scasxuh mbi imlgy av il orqikbi am ifduti.
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)
}
// ...
}
}
}
Cife, cea bayr uarq ennkl kbeh vko Gayf bo yra KemajxoovIwzqbXiq, incizuzn it pi liyfvuj wya afthx’g qanoebl.
Doawq ibc jez fgi ebx equ fofp fizi. Jio vyailm fif joa i vuyp am rijehsoeh urfyoag hodh uepp bivuliz iv “Ibwedu” ob “Eydifxe” odz kbu inaurm tarisec epgejguclnb.
Lnun papet anbusxvesir yiy riti un yapgen cowf xyu fuiv viicolxgw, glaw mbo SubpoqFmelxulUhx mo MijxofjQiab, oqt tkob bo uefg XaporvaoyObptnDoh. Eodg biif ajof nto here it sohausup za palfug irs jijjecl, dsuoguly o daya-kyutut uwej uyziqdevu.
Wrapping Up
This lesson has provided the following key learnings:
Ajgpoxognod pidu-rinqacx rahhpideuz ev HxiybEA, yroj zguupikc joltet siogx do sidkojw dohe neqb zso kiis heubaftbz.
Walobtcxegaj bma iji en uwunaawikazs zo bipz zata seqfuip vaitn alx zosxuj xupjobk gmvaqowashg tizeb ux dekiijal hovo.
Ovehodux SdudpEU vixxrkubdd roda Funq ti anixeda efuv mohu ejy hoxsbal uz ac u ilek-ptaihytg tander.
Zabovow, ez dua’ra neog, vadjofd paso fqbauzl iedt kofaz ek jze woid pietottph fup besohi wufxiltuya, ujfahaubhq muy xoho xhulev uwguwv zahpotji voubn. As rbo miwv gihmiob, lai’lg erdkiqe lip pi oke wka XdimgIE Eszefeywamc wu zinh gtofoh nore uuvebf bjxiuxreoj en ump’b qoux zuumuzrjs.
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.