You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Documentation/Manual.md
+42-1Lines changed: 42 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -177,10 +177,51 @@ Property declarations within `@Instantiable` types decorated with [`@Instantiate
177
177
178
178
Property declarations within `@Instantiable` types decorated with [`@Forwarded`](../Sources/SafeDI/Decorators/Forwarded.swift) represent dependencies that come from the runtime, e.g. user input or backend-delivered content. Like an `@Instantiated`-decorated property, a `@Forwarded`-decorated property is available to be `@Received` by objects instantiated further down the dependency tree.
179
179
180
-
A `@Forwarded` property is forwarded into the SafeDI dependency tree by a[`Instantiator`](#instantiator)’s `instantiate(_ forwardedProperties: T.ForwardedProperties) -> T` function that creates an instance of the property’s enclosing type.
180
+
A `@Forwarded` property is forwarded into the SafeDI dependency tree by an[`Instantiator`](#instantiator)’s `instantiate(_:)` function that creates an instance of the property’s enclosing type.
181
181
182
182
Forwarded property types do not need to be decorated with the `@Instantiable` macro.
183
183
184
+
Here’s an example showing how to forward a runtime value into an `@Instantiable` type:
185
+
186
+
```swift
187
+
// A view that requires a runtime value (the user’s name).
188
+
@Instantiable
189
+
publicstructLoggedInView: View, Instantiable {
190
+
publicinit(userName: String) {
191
+
self.userName= userName
192
+
}
193
+
194
+
publicvar body: some View {
195
+
Text("Hello, \(userName)")
196
+
}
197
+
198
+
@Forwardedprivatelet userName: String
199
+
}
200
+
201
+
// A view that creates LoggedInView when there is a user.
Property declarations within `@Instantiable` types decorated with [`@Received`](../Sources/SafeDI/Decorators/Received.swift) are injected into the enclosing type’s initializer. Received properties must be `@Instantiated` or `@Forwarded` by an object higher up in the dependency tree.
0 commit comments