Class
MutableInMemoryProvider
A configuration provider that stores mutable values in memory.
- iOS 18.0+
- macOS 15.0+
- tvOS 18.0+
- visionOS 2.0+
- watchOS 11.0+
final class MutableInMemoryProvider
Mentioned In
Overview
Unlike InMemoryProvider, this provider allows configuration values to be modified after initialization. It maintains thread-safe access to values and supports real-time notifications when values change, making it ideal for dynamic configuration scenarios.
Change notifications
The provider supports watching for configuration changes through the standard ConfigProvider watching methods. When a value changes, all active watchers are automatically notified with the new value.
Use cases
The mutable in-memory provider is particularly useful for:
Dynamic configuration: Values that change during application runtime
Configuration bridges: Adapting external configuration systems that push updates
Testing scenarios: Simulating configuration changes in unit tests
Feature flags: Runtime toggles that can be modified programmatically
Performance characteristics
This provider offers O(1) lookup time with minimal synchronization overhead. Value updates are atomic and efficiently notify only the relevant watchers.
Usage
// Create provider with initial values
let provider = MutableInMemoryProvider(initialValues: [
"feature.enabled": true,
"api.timeout": 30.0,
"database.host": "localhost"
])
let config = ConfigReader(provider: provider)
// Read initial values
let isEnabled = config.bool(forKey: "feature.enabled") // true
// Update values dynamically
provider.setValue(false, forKey: "feature.enabled")
// Read updated values
let stillEnabled = config.bool(forKey: "feature.enabled") // false
To learn more about the in-memory providers, check out Using in-memory providers.
Topics
Creating a mutable in-memory provider
Updating values in a mutable in-memory provider
Relationships
Conforms To