Skip to content

Commit 890b70f

Browse files
Add AppDelegate entry point example to prepareDependencies documentation (#316)
* Add AppDelegate entry point example to prepareDependencies documentation * Update WithDependencies.swift --------- Co-authored-by: Stephen Celis <[email protected]>
1 parent c81cb3d commit 890b70f

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

Sources/Dependencies/WithDependencies.swift

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,40 @@ import Foundation
44
///
55
/// > Important: A dependency key can be prepared at most a single time, and _must_ be prepared
66
/// > before it has been accessed. Call `prepareDependencies` as early as possible in your
7-
/// > application.
7+
/// > application, for example in your SwiftUI entry point:
8+
/// >
9+
/// > ```swift
10+
/// > @main
11+
/// > struct MyApp: App {
12+
/// > init() {
13+
/// > prepareDependencies {
14+
/// > $0.defaultDatabase = try! DatabaseQueue(/* ... */)
15+
/// > }
16+
/// > }
17+
/// >
18+
/// > // ...
19+
/// > }
20+
/// > ```
21+
/// >
22+
/// > Or your app delegate:
23+
/// >
24+
/// > ```swift
25+
/// > @main
26+
/// > class AppDelegate: UIResponder, UIApplicationDelegate {
27+
/// > func application(
28+
/// > _ application: UIApplication,
29+
/// > didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
30+
/// > ) -> Bool {
31+
/// > prepareDependencies {
32+
/// > $0.defaultDatabase = try! DatabaseQueue(/* ... */)
33+
/// > }
34+
/// > // Override point for customization after application launch.
35+
/// > return true
36+
/// > }
37+
/// >
38+
/// > // ...
39+
/// > }
40+
/// > ```
841
///
942
/// - Parameter updateValues: A closure for updating the current dependency values for the
1043
/// lifetime of your application.

0 commit comments

Comments
 (0)