Structure
InMemoryProvider
A configuration provider that stores values in memory.
- iOS 18.0+
- macOS 15.0+
- tvOS 18.0+
- visionOS 2.0+
- watchOS 11.0+
struct InMemoryProvider
Mentioned In
Overview
This provider maintains a static dictionary of configuration values in memory, making it ideal for providing default values, overrides, or test configurations. Values are immutable once the provider is created and never change over time.
Use cases
The in-memory provider is particularly useful for:
Default configurations: Providing fallback values when other providers don’t have a value
Configuration overrides: Taking precedence over other providers
Testing: Creating predictable configuration states for unit tests
Static configurations: Embedding compile-time configuration values
Value types
The provider supports all standard configuration value types and automatically handles type validation. Values must match the requested type exactly - no automatic conversion is performed - for example, requesting a String value for a key that stores an Int value will throw an error.
Performance characteristics
This provider offers O(1) lookup time and performs no I/O operations. All values are stored in memory.
Usage
let provider = InMemoryProvider(values: [
"http.client.user-agent": "Config/1.0 (Test)",
"http.client.timeout": 15.0,
"http.secret": ConfigValue("s3cret", isSecret: true),
"http.version": 2,
"enabled": true
])
// Prints all values, redacts "http.secret" automatically.
print(provider)
let config = ConfigReader(provider: provider)
let isEnabled = config.bool(forKey: "enabled", default: false)
To learn more about the in-memory providers, check out Using in-memory providers.
Topics
Creating an in-memory provider
Relationships
Conforms To