Achievement unlocked - SwiftUI. I had mastered SwiftUI few months back. It took me a while to fully grasp all these concepts in the framework. Programming in SwiftUI is that pleasant experience. I am using iOS 17 and above using the new state management methods and not Combine.
I will provide an example of how I implemented theming of the entire app using SwiftUI. It's basically changing the font colour and tint colour of all the UI components based on the selected colour scheme like we have in macOS accent colour.


First the theme picker circles view.
Here when the theme circle is tapped, it saves the selected theme to the environment which is available throughout the app. This is set in the main file MainViewPhone.swift
.
The SettingsView.swift
is as follows.
The MainViewPhone.swift
is as follows.
Here we can see that the theme is stored in a state variable and added to the environment. And accent color and tint uses that value. So any change in the environment variable reflects in the state and will retrigger the draw which will update these UI elements.
The UIViewState.swift
is as follows.
Finally the utils class EAUtils.swift
.
This is all dynamic and requires no app restart.