@@ -1,24 +0,0 @@
-//
-// ContentView.swift
-// SUIExamples
-// Created by Pavel Yurchenko on 17.08.2024.
-
-import SwiftUI
-struct ContentView: View {
- var body: some View {
- VStack {
- Image(systemName: "globe")
- .imageScale(.large)
- .foregroundStyle(.tint)
- Text("Hello, world!")
- }
- .padding()
-}
-#Preview {
- ContentView()
@@ -0,0 +1,14 @@
+//
+// DI.swift
+// SUIExamples
+// Created by Pavel Yurchenko on 27.11.2024.
+
+import Foundation
+final class DI {
+ static var shared: DI = .init()
+ let navigationStack = NavigatorStack()
+}
@@ -0,0 +1,21 @@
+// MainBuilder.swift
+import SwiftUI
+struct MainBuilder {
+ func build() -> some View {
+ let navigatorStack = DI.shared.navigationStack
+ return MainView()
+ .environment(
+ MainVM(
+ navigatorStack: navigatorStack
+ )
+ }
@@ -0,0 +1,18 @@
+// MainVM.swift
+@Observable
+final class MainVM {
+ private(set) var navigatorStack: NavigatorStack
+ init(navigatorStack: NavigatorStack) {
+ self.navigatorStack = navigatorStack
@@ -0,0 +1,34 @@
+// MainView.swift
+// Created by Pavel Yurchenko on 17.08.2024.
+struct MainView: View {
+ @Environment(MainVM.self) private var vm
+ var body: some View {
+ VStack {
+ Button("Products") {
+ vm.navigatorStack.push(.products)
+ Button("Product 1") {
+ vm.navigatorStack.push(.product(id: 1))
+ Button("Cart") {
+ vm.navigatorStack.push(.cart)
+ Button("Feedback") {
+ vm.navigatorStack.push(.feedback)
+ .padding()
+#Preview {
+ MainBuilder().build()
@@ -0,0 +1,23 @@
+// NavigatorStack.swift
+final class NavigatorStack: ObservableObject {
+ @Published
+ var path = NavigationPath()
+ func push(_ route: Route) {
+ path.append(route)
+ func pop() {
+ path.removeLast()
@@ -0,0 +1,31 @@
+// Route.swift
+enum Route: Hashable {
+ case main
+ case products
+ case product(id: Int)
+ case cart
+ case feedback
+ func buildModule() -> some View {
+ return switch self {
+ case .main:
+ case .products:
+ case .product:
+ case .cart:
+ case .feedback:
@@ -9,9 +9,17 @@ import SwiftUI
@main
struct SUIExamplesApp: App {
+ @StateObject private var navigatorStack: NavigatorStack = DI.shared.navigationStack
var body: some Scene {
WindowGroup {
+ NavigationStack(path: $navigatorStack.path){
+ .navigationDestination(for: Route.self) {
+ $0.buildModule()
}