Skip to content

Commit

Permalink
[#44] Updated README for UserDefaultsStore (#46)
Browse files Browse the repository at this point in the history
* Described how `UserDefaults` can be used to read and write feature flag values
* Updated the code example in Usage
  • Loading branch information
yakovmanshin authored Mar 28, 2021
1 parent 093ee8f commit c35bef7
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit c35bef7

Please sign in to comment.