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: Sources/Configuration/Documentation.docc/Documentation.md
+2-3Lines changed: 2 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -120,7 +120,7 @@ For example, to read the timeout configuration value for an HTTP client, check o
120
120
```swift
121
121
// Environment variables consulted first, then JSON.
122
122
let primaryProvider = EnvironmentVariablesProvider()
123
-
let secondaryProvider = try await JSONProvider(
123
+
let secondaryProvider = try await FileProvider<JSONSnapshot>(
124
124
filePath: "/etc/config.json"
125
125
)
126
126
let config = ConfigReader(providers: [
@@ -246,8 +246,7 @@ You can also implement a custom ``ConfigProvider``.
246
246
In addition to using providers individually, you can create fallback behavior using an array of providers.
247
247
The first provider that returns a non-nil value wins.
248
248
249
-
The following example illustrates a hierarchy of provides, with environmental variables overrides winning
250
-
over command line arguments, a file at `/etc/config.json`, and in-memory defaults:
249
+
The following example shows a provider hierarchy where environment variables take precedence over command line arguments, a JSON file, and in-memory defaults:
251
250
252
251
```swift
253
252
// Create a hierarchy of providers with fallback behavior.
Copy file name to clipboardExpand all lines: Sources/Configuration/Documentation.docc/Guides/Best-practices.md
+10-14Lines changed: 10 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,20 +4,18 @@ Follow these principles to make your code easily configurable and composable wit
4
4
5
5
## Overview
6
6
7
-
When designing configuration for your Swift libraries and applications, following established patterns helps create
8
-
a consistent and maintainable experience for developers. These best practices ensure your configuration integrates
9
-
well with the broader Swift ecosystem.
7
+
When designing configuration for Swift libraries and applications, follow these patterns to create consistent, maintainable code that integrates well with the Swift ecosystem.
10
8
11
9
### Document configuration keys
12
10
13
-
Include comprehensive documentation about what configuration keys your library reads. For each key, document:
11
+
Include thorough documentation about what configuration keys your library reads. For each key, document:
14
12
15
-
- The key name and its hierarchical structure
16
-
- The expected data type
17
-
- Whether the key is required or optional
18
-
- Default values when applicable
19
-
- Valid value ranges or constraints
20
-
- Usage examples
13
+
- The key name and its hierarchical structure.
14
+
- The expected data type.
15
+
- Whether the key is required or optional.
16
+
- Default values when applicable.
17
+
- Valid value ranges or constraints.
18
+
- Usage examples.
21
19
22
20
```swift
23
21
publicstructHTTPClientConfiguration {
@@ -38,8 +36,7 @@ public struct HTTPClientConfiguration {
38
36
39
37
### Use sensible defaults
40
38
41
-
Provide reasonable default values whenever possible to make your library work without extensive configuration.
42
-
This reduces the barrier to adoption and ensures your library works out of the box for common use cases.
39
+
Provide reasonable default values to make your library work without extensive configuration.
43
40
44
41
```swift
45
42
// Good: Provides sensible defaults
@@ -114,8 +111,7 @@ For more details, check out <doc:Choosing-reader-methods>.
114
111
115
112
### Validate configuration values
116
113
117
-
Consider validating configuration values and throwing meaningful errors if they're invalid. This helps
118
-
developers catch configuration issues early.
114
+
Validate configuration values and throw meaningful errors for invalid input to catch configuration issues early.
Copy file name to clipboardExpand all lines: Sources/Configuration/Documentation.docc/Guides/Choosing-access-patterns.md
+17-26Lines changed: 17 additions & 26 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,8 +4,7 @@ Learn how to select the right method for reading configuration values based on y
4
4
5
5
## Overview
6
6
7
-
Swift Configuration provides three access patterns for retrieving configuration values, each optimized
8
-
for different use cases and performance requirements.
7
+
Swift Configuration provides three access patterns for retrieving configuration values, each optimized for different use cases and performance requirements.
9
8
10
9
The three access patterns are:
11
10
@@ -44,13 +43,11 @@ Use the "get" pattern when:
44
43
45
44
- Returns the currently cached value from the provider.
46
45
- No network or I/O operations occur during the call.
47
-
- Values may become stale if the underlying data source changes and the provider is either non-reloading, or
48
-
has a long reload interval.
46
+
- Values may become stale if the underlying data source changes and the provider is either non-reloading, or has a long reload interval.
49
47
50
48
### Fetch: Asynchronous fresh access
51
49
52
-
The "fetch" pattern asynchronously retrieves the most current value from the authoritative data source. This ensures
53
-
you always get up-to-date configuration, even if it requires network calls or file system access.
50
+
The "fetch" pattern asynchronously retrieves the most current value from the authoritative data source, ensuring you always get up-to-date configuration.
54
51
55
52
```swift
56
53
let config =ConfigReader(provider: remoteConfigProvider)
@@ -74,13 +71,12 @@ let dbConnectionString = try await config.fetchRequiredString(
74
71
75
72
#### When to use
76
73
77
-
Use the `fetch` pattern when:
74
+
Use the "fetch" pattern when:
78
75
79
76
-**Freshness is critical**: You need the latest configuration values.
80
77
-**Remote providers**: Using configuration services, databases, or external APIs that perform evaluation remotely.
81
78
-**Infrequent access**: Reading configuration occasionally, not in hot paths.
82
-
-**Setup operations**: Configuring long-lived resources like database connections where one-time overhead isn't
83
-
a concern, and the improved freshness is important.
79
+
-**Setup operations**: Configuring long-lived resources like database connections where one-time overhead isn't a concern, and the improved freshness is important.
84
80
-**Administrative operations**: Fetching current settings for management interfaces.
0 commit comments