@@ -72,52 +72,50 @@ public class NavigationStack: ObservableObject {
72
72
}
73
73
}
74
74
}
75
+ }
75
76
76
- //the actual stack
77
- private struct ViewStack {
78
- private var views = [ ViewElement] ( )
77
+ private struct ViewStack {
78
+ private var views = [ ViewElement] ( )
79
79
80
- func peek( ) -> ViewElement ? {
81
- views. last
82
- }
80
+ func peek( ) -> ViewElement ? {
81
+ views. last
82
+ }
83
83
84
- var depth : Int {
85
- views. count
86
- }
84
+ var depth : Int {
85
+ views. count
86
+ }
87
87
88
- mutating func push( _ element: ViewElement ) {
89
- guard indexForView ( withId: element. id) == nil else {
90
- print ( " Duplicated view identifier: \" \( element. id) \" . You are trying to push a view with an identifier that already exists on the navigation stack. " )
91
- return
92
- }
93
- views. append ( element)
88
+ mutating func push( _ element: ViewElement ) {
89
+ guard indexForView ( withId: element. id) == nil else {
90
+ print ( " Duplicated view identifier: \" \( element. id) \" . You are trying to push a view with an identifier that already exists on the navigation stack. " )
91
+ return
94
92
}
93
+ views. append ( element)
94
+ }
95
95
96
- mutating func popToPrevious( ) {
97
- _ = views. popLast ( )
98
- }
96
+ mutating func popToPrevious( ) {
97
+ _ = views. popLast ( )
98
+ }
99
99
100
- mutating func popToView( withId identifier: String ) {
101
- guard let viewIndex = indexForView ( withId: identifier) else {
102
- print ( " Identifier \" \( identifier) \" not found. You are trying to pop to a view that doesn't exist. " )
103
- return
104
- }
105
- views. removeLast ( views. count - ( viewIndex + 1 ) )
100
+ mutating func popToView( withId identifier: String ) {
101
+ guard let viewIndex = indexForView ( withId: identifier) else {
102
+ print ( " Identifier \" \( identifier) \" not found. You are trying to pop to a view that doesn't exist. " )
103
+ return
106
104
}
105
+ views. removeLast ( views. count - ( viewIndex + 1 ) )
106
+ }
107
107
108
- mutating func popToRoot( ) {
109
- views. removeAll ( )
110
- }
108
+ mutating func popToRoot( ) {
109
+ views. removeAll ( )
110
+ }
111
111
112
- private func indexForView( withId identifier: String ) -> Int ? {
113
- views. firstIndex {
114
- $0. id == identifier
115
- }
112
+ func indexForView( withId identifier: String ) -> Int ? {
113
+ views. firstIndex {
114
+ $0. id == identifier
116
115
}
117
116
}
118
117
}
119
118
120
- //the actual element in the stack
121
119
struct ViewElement : Identifiable , Equatable {
122
120
let id : String
123
121
let wrappedElement : AnyView
0 commit comments