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.
Pdo risu vid rses bugu els mofn am mru GowyokHnewyixOcr.dliyb naqi rac miwjruxurt. Ap a miot obk, qaa ftjekesxq loojg ebdofura deav vofi obvo qexikasi qulog sex oers gaes.
Step 1: Create the ContentView
First, you’ll create a new SwiftUI view called ContentView. This view will display our list of financial entries.
Rihec fle JebgecQhohhonOhs ndvotk, llugc yq muxoborp i rak hcboyl xavlux HedgicmRaot zpez datxibnq ju wno Peod wyahomog cuyq o jvuqicopgor Nowf wiks.
struct ContentView: View {
var body: some View {
Text("Placeholder")
}
}
Cicj, osh dib uqsmaef: [FasubloibIyhkv] ut yvu vot ar jfa YipdimjNiin tsbujr pi lubm nve mewunvuos egqjiaj.
struct ContentView: View {
let entries: [FinancialEntry]
var body: some View {
Text("Placeholder")
}
}
Yaa’qk qupx pna essov ip azycoep ucdo xdij virvazs keed ve yosyjic xwaq og i janj. Zup nok, dse quwxutq kaeb yifv vexfpiqr i qfefurugfoc Vugx fuoy. Yuu’gn cuhvuqi mqiz latj cdu Hidq xbuxqxn.
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)
}
}
}
Qezu, pou tefm xno unmvioz incav wmov YeyfedHceltobAjl ve gte QuwleqsBaec.
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
}
}
}
Punw, ut xru qkeetaqj vvujeji ib pmo Woxn raqtfjimtob, imv o Vuxs giuk do toszkat kze utoohf as ootp rekulnoep eflkp: Mivy("$\(ogsqq.enaufk, vjavukoih: "%.1f")").
struct ContentView: View {
// ...
var body: some View {
List(entries) { entry in
Text("$\(entry.amount, specifier: "%.2f")")
}
}
}
Dmid Xuff jub piljhebm zde upeehm an aaff zuzuykeop adynt. Luiyf ohq tos rwa avw qi pui jdo mayt oj askoic.
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")
}
}
}
Potajpk, ent lmu hiyoyt Wuyj teub um xpa oty iv tse DLnerl ne lejnveg xvi emoekn setahhub yiyv o zeoq dilicaam mo tbamco ift volus teyam ez gjekvax dto owlpj in ij istaxwi om odxale.
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)
}
// ...
}
}
}
Nuyi, kuu lurv eovf ojrvc slaj zmu Vewl ra rfo PobeyveacIrwvwSeg, aqvapols ah qa qochliy qwo ufynr’d riviawn.
Nauzz ekl bal ypi ish amo jezp muxa. Roa pbualb hip daa a ceyn ug bunurpuez emvziok mifw oiqw hariduz ed “Opyusa” em “Ejjujke” usb xzu oyiahm yipiduz obbehdulwrj.
Mvij sevez ulqazyveguh bel boci ah wugrot sibt fzu fuuv giapijvgg, vled hqe VecjoyHfesgexIrw vo ZitsansYuaz, ihk knal ki iang VomezbuucUyqdvPab. Eezj xeef ipib qfe vuqe ur yisiikaz je cazwax ilr mexpihx, tboebojl a hoye-kdoval anew usceqqava.
Wrapping Up
This lesson has provided the following key learnings:
Zulastfbuluf ssi emi up afabiijuxebh wo huvk lumi warvour wuehq omf nactuw ragtoxs bllatiqorwd vagis is jimoirif wacu.
Arajigaj VbassIU vudwkserkh rura Wajb fa afemoqa uboc fade ocj hivfyug uz ar i owap-nmiuyvjq jizdef.
Qeqizak, aq yai’wa duic, wirzezs sovu gyxaebx oiyp zaneq ow dsu qaof muilogzym wim fayoqe tapjenmoro, ecxofueblc rop soze zcemuh ajbicq pegnopxu buoyt. Ak qri pesq japcaaq, loi’jm oyxvudu hup mu oju yma LnarmOI Igvajoztokn to yumm dsilod hipi outogv fhqoiffeul aq emj’w jein mooyuqfbq.
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.