Skip to content

Commit

Permalink
Updated Usage
Browse files Browse the repository at this point in the history
  • Loading branch information
yakovmanshin committed Apr 26, 2024
1 parent 5997ea7 commit cf71711
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ Alternatively, you can create a custom wrapper object. That’s what I tend to d
</details>

## Usage
Here’s the most basic way to use YMFF:
Here’s how you declare feature flags with YMFF:

```swift
import YMFF
Expand All @@ -111,25 +111,25 @@ enum FeatureFlags {
// `resolver` references one or more feature flag stores.
private static var resolver = FeatureFlagResolver(configuration: .init(stores: [
// If you want to change feature flag values from within your app, you’ll need at least one mutable store.
// `RuntimeOverridesStore` is a YMFF-supplied object. It stores modified values until the app restarts.
.mutable(RuntimeOverridesStore()),
// `MyFeatureFlagStore.shared` conforms to `FeatureFlagStoreProtocol`.
// `MyFeatureFlagStore.shared` is your object, conforming to `FeatureFlagStoreProtocol`.
.immutable(MyFeatureFlagStore.shared),
]))

// Feature flags are initialized with three pieces of data:
// a key string, the default value (used as fallback
// when all feature flag stores fail to provide one), and the resolver.
// a key string, the default (fallback) value, and the resolver.
@FeatureFlag("promo_enabled", default: false, resolver: resolver)
static var promoEnabled

// Feature flags aren't limited to booleans. You can use any type of value.
// Feature flags arent limited to booleans. You can use any type of value!
@FeatureFlag("number_of_banners", default: 3, resolver: resolver)
static var numberOfBanners

// Sometimes it may be convenient to transform the raw value—the one you receive from the store
// to the native value—the one used in your app.
// In the following example, `MyFeatureFlagStore` stores values as strings, but the app uses an enum.
// To switch between the types, you use a `FeatureFlagValueTransformer`.
// Advanced: Sometimes you want to map raw values from the store
// to native values used in your app. `MyFeatureFlagStore` below
// stores values as strings, while the app uses an enum.
// To switch between them, you use a `FeatureFlagValueTransformer`.
@FeatureFlag(
"promo_unit_kind",
FeatureFlagValueTransformer { string in
Expand All @@ -144,7 +144,7 @@ enum FeatureFlags {

}

// You can create feature flags of any type.
// You can use custom types for feature-flag values.
enum PromoUnitKind: String {
case text
case image
Expand Down

0 comments on commit cf71711

Please sign in to comment.