Skip to content

Commit 4980742

Browse files
author
Peter Major
committed
Add @OptionalInjected to documentation
1 parent 8b2bc11 commit 4980742

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

Documentation/Annotation.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,18 @@ class NamedInjectedViewController: UIViewController {
5656
```
5757
If you go this route just make sure you specify the name *before* accessing the injected service for the first time.
5858

59+
### Optional injection
60+
61+
An annotation is available that supports optional resolving. If the service is not registered, then the value will be nil, otherwise it will be not nil:
62+
```
63+
class InjectedViewController: UIViewController {
64+
@OptionalInjected var service: XYZService?
65+
func load() {
66+
service?.load()
67+
}
68+
}
69+
```
70+
5971
### Custom Containers
6072

6173
You can specify and resolve custom containers using Injected. Just define your custom container...

Documentation/Optionals.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,15 @@ This could be helpful if for some reason you wanted to resolve to a specific ins
5454
```swift
5555
var abc: ABCServicing? = Resolver.resolve(ABCService.self)
5656
```
57+
58+
## Optional annotation
59+
60+
An annotation is available that supports optional resolving. If the service is not registered, then the value will be nil, otherwise it will be not nil:
61+
```
62+
class InjectedViewController: UIViewController {
63+
@OptionalInjected var service: XYZService?
64+
func load() {
65+
service?.load()
66+
}
67+
}
68+
```

0 commit comments

Comments
 (0)