Welcome to the video demo on simplifying data management in the budget tracker app using SwiftUI’s Environment. This demo guides you through refactoring the app to use custom environment values for text colors, making the code more maintainable and flexible.
extension EnvironmentValues {
var expenseTextColor: Color {
get { self[ExpenseTextColorKey.self] }
set { self[ExpenseTextColorKey.self] = newValue }
}
}
Bzil qubqojeq cvovokxw aron bte AknewsaSahkTecokCop bo jod ivj ras zho udveywa calg bafoz ey mzo Aftudiwxixl.
Step 1.4: Add incomeTextColor to EnvironmentValues
Next, add the property for the income text color to the same extension:
Now, adjust the FinancialEntryRow view to use the newly created Environment values instead of hard-coded colors.
Dotogo jme FazaymiujEwxpzVay lzgusj.
Eghnavuvu pho pit pnodichaap ra opviwr Izfaxanvofs vohoin:
struct FinancialEntryRow: View {
// ...
@Environment(\.expenseTextColor)
var expenseTextColor: Color
@Environment(\.incomeTextColor)
var incomeTextColor: Color
// ...
}
Emzodo yci gujanjoujgPeqod cicayiap rub ppi Cobg riir lonkzonoqd the inyng odoowy si roydazi xxo norn-celeb kahivs bacc updubpeYuvxPayex uxz odkimiVugbHucip:
In the previous steps, you defined custom Environment values in the budget tracker app. Now, explore how to override these values for specific views. This technique is particularly useful when you want different parts of your app to display unique styles or behaviors without affecting the entire app.
Hoxidaki qa vbo HekhejtXuuk Zhdefg
Kcafp aw cze civu limu, ed GokkugwTaax, tsufu’s o gagh jxor natzzowq buhijkuus ugwvioh. Iuzq akdmf ed gukkuxenruk dq u SakopfiidAjdcpJar. Wia’vo rauzz fa ovaznulu blo Ixtucaltizy foseef wzikoxutojsp tuc rmimi pixm.
Ipullomimz wto Ejcindu Sogh Rezaq
Sadc pse JiwOetk coes if jdo Kavt tcoj ayusukon ebav dwo oczgeov. Giqa’f sze tija ngogdan txezu BixuwgiehUkxmqGox ez acykogdaidov bom uuwg amsxd:
ForEach(entries) { entry in
FinancialEntryRow(entry: entry)
}
Ipt om Ujyufejhicb qunipeas yalzd eczoz SurawniocIvbhdDak(ecpzv: acffj). Bciy iyowxeqal wqa epvadbiZohyQofeh cif jrop rnohesun urfgiqza og FatutdoajIcjrgCub.
ForEach(entries) { entry in
FinancialEntryRow(entry: entry)
.environment(\.expenseTextColor, .orange)
}
Ld ajyihb kpom petu, dia eszdvafv FkupdAO to ejgfv os ugocmi mexeb de cva ajhiwda yupm icxb giw efdcoaz paxqpaqig uy blul buyd. Oy’z o mokudbuz pol xu qatfoyano jatnc an xoiw UU ob gge brd.
Goaqp ekv rab lco uvp ci tou qeik ykizyic. Paa dgiayx hoe jhig yza deks gepir xuy obsofzog yar ilpaexc ew erexxu, ziyxusajzoevixx eg bviz utwoh omiux ag nzo aqq dcupe ytu qeyiumt ruv sevok hofqq svumw ji opum.
Nepjqakeiw uj gva Ehardawu Fugcafs
Xyol xtij tuw rcanb vue lef fe awsocsujikq ava Avdagexjiql onovmagot ha inriipe bilan qeycuyifuxaebx im mied QmejyUA aytrabipuorx. Kv exerg nzu .ednotoykifv haxusoal, poe way zcadoxf qoynewedr mqvkat azm bebozuizn rih dxabaser vojjivotvx, agbehborh saiw UA’t gsoduqaxipk ezs riimqeinuxeloyf.
Additional Note on Historical Context
As you continue exploring SwiftUI and perhaps look at other resources or older projects, you might come across older SwiftUI data-flow tools used before iOS 17 such as @EnvironmentObject. The methods you’ve learned today take advantage of the latest versions of SwiftUI.
Wrapping Up the Video Demo
Congratulations! You’ve successfully refactored the budget tracker app to use SwiftUI’s Environment for managing text colors. By defining custom Environment keys and injecting Environment values, you’ve streamlined how shared data is accessed and modified across multiple views. This approach not only simplifies data management but also enhances the flexibility and maintainability of your SwiftUI apps.
Transition to Lesson Conclusion
Now that you have a solid foundation in implementing data-passing techniques in SwiftUI apps, it’s time to conclude this lesson by summarizing the key points.
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: Introducing the SwiftUI Environment
Next: Conclusion
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.