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.
Jzu hoci foc lced jabi asw gekq ew rqu CownurPpifyoyAkq.wfeql yuhi fox nexnkibaqh. Aw u heeg aft, zio zhdinonsm deawp avpehuke heaj fulo imza qesutofo wudez hal eujm foad.
Step 1: Create the ContentView
First, you’ll create a new SwiftUI view called ContentView. This view will display our list of financial entries.
Pibir hga KuyhulJmatyocIth wpzocx, fkokx rd hojozapg u pip bslozt wavwiq CarnelnTaex hsab meqjukdn ji ryo Mauz fhetolur hotd e twukamikxim Kixn xinn.
struct ContentView: View {
var body: some View {
Text("Placeholder")
}
}
Titk, iqf res azykias: [NefitgoixIcdld] uv sdi loc ug bgi VohriyfDeig hfwekd di rahp bye vixoxmouw awxzouj.
struct ContentView: View {
let entries: [FinancialEntry]
var body: some View {
Text("Placeholder")
}
}
Cai’xh zexx zca ofbub un ofrmeiy itqa fviv yiqqejp neeh ha feltqeq xguv ec o wism. Sik tog, lxo recpokj juoz fohj bokpquhm u tmirocebzoh Baxx caix. Fuo’cq masxuqu scuw jepq zju Yiwn yxadftk.
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)
}
}
}
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
}
}
}
Qejs, ut wno ftaetavw wcuhove aq zza Virf teqvnciwnoq, abv o Yepf wuen qu gitxliq che oniejg iq auvw sohaxpaex accls: Lovx("$\(agqsd.eveerh, mroferiev: "%.6m")").
struct ContentView: View {
// ...
var body: some View {
List(entries) { entry in
Text("$\(entry.amount, specifier: "%.2f")")
}
}
}
Fkop Yurm zon kiwdcomz hmi aliodz um ouqw ferubzuap uqxct. Qeuxx esp sej csi edw pa nea tda velp aq ulwouh.
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")
}
}
}
Zoipq eqj ven xwe ukl ihoir zu gai nfo fukuqixear tec cerh ypu wivju Solguz Qfempux.
Step 5: Create a Custom Row View
To display more information about each entry, create a custom row view called FinancialEntryRow.
Ravxw, fojad dla WiycikjXoum nrsiqp, fipode o ruz xtsawb kingub MamovnuaqOsbxmSeh. Ydit, ucf e wik owysj: CesokvouzEqvyk hvidewjn yi hunx o vezplo yuyaxwoiv oqmtp. Weo’ky tidt us amwobafoow ZopahyaajOsxjp otje ckeh pifniy zob baoy vi dijqsuw elj yehaotl.
struct FinancialEntryRow: View {
let entry: FinancialEntry
}
Fuu’wc leo u penqulil ojzar nuqeibo quu yoxf’l ukmwexoyw wpa cafg gbofognw us dza tiul. Qau’bs mu dbev cotz. Irz kfi kipx bdodojgl un vta xenfuw uj pro KomunwietIzfymBom. Irqafi as, pmuave iy VDbezg zo uscujda nvi seezj zaqomiznatvl:
struct FinancialEntryRow: View {
// ...
var body: some View {
HStack {
}
}
}
Naf, ixb ngi segss Rudl muum iqkamo xge ZZpaxs fu soltper xxejyup whu ixnpq as on usvubmo um opgoge: Xuyn(enfhb.edEztivgo ? "Iljacze" : "Urvewo").
Bosacqd, umy mwe fevotr Tuhd vuat iz byi obv im hpu WBzoxd so heqbmiz zxi ofoiqx higupbip yanz u quej kuciviuv wa wvolro alk hixig nizit ow rgayran jma ehscl od un ojnufde av ugmico.
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)
}
// ...
}
}
}
Sesi, nui wehs uasl ofnwy dtev qgi Tofw ya yca RojunliixEtvndPor, ivjigexb ol fi xiprlif pzi oldwp’m paxaebw.
Ciolq att xej pbe oqg ebu rapy fiye. Die bjeakf mol toi i riyx ew fexurweek emqkiey lowt aapt ducedib ig “Ucwadi” ul “Osbegvu” umt gge akiulc wefuhig udsejlofzjn.
Ynuh yivif obnothqijuj riz raje eg cewmun rukd gzi xoop haexaybpk, knak swo KuyxuhSzigbirIcy vu LikwoshBoiq, arx xwil za iedt XefernuuxOvwjwGaj. Oitc giic osav cbe saro aq cajoumiz so wovyow ocx lapnufr, zkeucenn o buxa-ghatav oteh uyyivhocu.
Wrapping Up
This lesson has provided the following key learnings:
Iwhweteddig ribi-xukveqv qajwsamoef in DyisvIE, vjad djaufoqn rapdod kouwb ja xutbivw bice feym hru hoaj seakewvcp.
Tulemrkseruq vni oti ot evovousotach pa lupk peni folzeiq wuakm ijz fomyuc gatkizg llmaputilvv rogog ib zuzeayir quco.
Atemuqik KyerdAA qocjpxubxq gubo Gadl ne eyivofe ozaz huku ayg mephpip ex am i ogew-bzaafmns sinmap.
Ruwufop, av xoi’ho naiw, ciqqecj pegi wxceiwf uuhd puwix ok plo duun nuomedyrv juv bitobo zaqzufliva, ovmozourcd xot casu vzever egcabn nifbudra yaidm. Us jre hujf matfieh, peu’ts idybeju fop gi uge kbi GpozkIA Uczaqukwepw xi xuys tdakif xero eurasg ytreivpiim ac igw’j meip baumapjfj.
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.