From c35bef79957d1286ceb827f4375f6912bbfe1fbf Mon Sep 17 00:00:00 2001 From: Yakov Manshin Date: Sun, 28 Mar 2021 22:46:07 +0300 Subject: [PATCH] [#44] Updated README for UserDefaultsStore (#46) * Described how `UserDefaults` can be used to read and write feature flag values * Updated the code example in Usage --- README.md | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index c67b3e1..7a705d4 100644 --- a/README.md +++ b/README.md @@ -71,11 +71,9 @@ enum FeatureFlags { // `resolver` references one or more feature flag stores. // `MyFeatureFlagStore.shared` conforms to `FeatureFlagStoreProtocol`. - private static var resolver: FeatureFlagResolverProtocol = { - FeatureFlagResolver(configuration: .init(persistentStores: [ - .opaque(MyFeatureFlagStore.shared) - ])) - } + private static var resolver = FeatureFlagResolver(configuration: .init( + persistentStores: [.opaque(MyFeatureFlagStore.shared)] + )) // Feature flags are initialized with three pieces of data: // a key string, the default value (used as fallback @@ -118,6 +116,25 @@ To remove the override and revert to using values from persistent stores, you ca FeatureFlags.$promoEnabled.removeRuntimeOverride() ``` +### `UserDefaults` + +Since v1.2.0, you can use `UserDefaults` to read and write feature flag values. Just pass an instance of `UserDefaultsStore` as `runtimeStore` in `FeatureFlagResolverConfiguration`. + +For backward-compatibility reasons, **you can’t use `UserDefaultsStore` and the in-memory `RuntimeOverridesStore` at the same time**. But [it’ll get better in v2](https://github.com/yakovmanshin/YMFF/issues/41). + +```swift +import Foundation + +// The `UserDefaultsStore` store must be both added in `persistentStores` +// and, most importantly, set as the `runtimeStore`. +private static var resolver = FeatureFlagResolver(configuration: .init( + persistentStores: [.userDefaults(UserDefaults.standard)], + runtimeStore: UserDefaultsStore() +)) +``` + +### More + You can browse the source files to learn more about the options available to you. An extended documentation is coming later. ## Contributing