@@ -42,6 +42,22 @@ Notice that the trailing closure is handed a binding to the unwrapped state. Thi
42
42
handed to the child view, and any changes made by the parent will be reflected in the child, and
43
43
vice-versa.
44
44
45
+ However, this does not compile just yet because ` sheet(item:) ` requires that the item being
46
+ presented conform to ` Identifable ` , and ` Int ` does not conform. This library comes with an overload
47
+ of ` sheet ` , called `` SwiftUI/View/sheet(item:id:onDismiss:content:)-1hi9l `` , that allows you to
48
+ specify the ID of the item being presented:
49
+
50
+ ``` swift
51
+ var body: some View {
52
+ List {
53
+ // ...
54
+ }
55
+ .sheet (item : $destination, id : \.self ) { $number in
56
+ CounterView (number : $number)
57
+ }
58
+ }
59
+ ```
60
+
45
61
Sometimes it is not optimal to model presentation destinations as optionals. In particular, if a
46
62
feature can navigate to multiple, mutually exclusive screens, then an enum is more appropriate.
47
63
@@ -65,15 +81,15 @@ var body: some View {
65
81
List {
66
82
// ...
67
83
}
68
- .sheet (item : $destination.counter ) { $number in
84
+ .sheet (item : $destination.counter , id : \. self ) { $number in
69
85
CounterView (number : $number)
70
86
}
71
87
}
72
88
```
73
89
74
90
### Popovers
75
91
76
- Popovers work similarly to covers . If the popover's state is represented as an optional you can do
92
+ Popovers work similarly to sheets . If the popover's state is represented as an optional you can do
77
93
the following:
78
94
79
95
``` swift
@@ -84,7 +100,7 @@ struct ContentView: View {
84
100
List {
85
101
// ...
86
102
}
87
- .popover (item : $destination) { $number in
103
+ .popover (item : $destination, id : \. self ) { $number in
88
104
CounterView (number : $number)
89
105
}
90
106
}
@@ -107,7 +123,7 @@ struct ContentView: View {
107
123
List {
108
124
// ...
109
125
}
110
- .popover (item : $destination.counter ) { $number in
126
+ .popover (item : $destination.counter , id : \. self ) { $number in
111
127
CounterView (number : $number)
112
128
}
113
129
}
@@ -116,7 +132,7 @@ struct ContentView: View {
116
132
117
133
### Covers
118
134
119
- Full screen covers work similarly to covers and sheets . If the cover's state is represented as an
135
+ Full screen covers work similarly to sheets and popovers . If the cover's state is represented as an
120
136
optional you can do the following:
121
137
122
138
``` swift
@@ -127,7 +143,7 @@ struct ContentView: View {
127
143
List {
128
144
// ...
129
145
}
130
- .fullscreenCover (item : $destination) { $number in
146
+ .fullscreenCover (item : $destination, id : \. self ) { $number in
131
147
CounterView (number : $number)
132
148
}
133
149
}
@@ -150,7 +166,7 @@ struct ContentView: View {
150
166
List {
151
167
// ...
152
168
}
153
- .fullscreenCover (item : $destination.counter ) { $number in
169
+ .fullscreenCover (item : $destination.counter , id : \. self ) { $number in
154
170
CounterView (number : $number)
155
171
}
156
172
}
0 commit comments