Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Give the opportunity to alter the default value of a Flag #15

Closed
malcommac opened this issue Jan 26, 2022 · 1 comment
Closed

Give the opportunity to alter the default value of a Flag #15

malcommac opened this issue Jan 26, 2022 · 1 comment
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@malcommac
Copy link
Collaborator

Feature Request

Give the opportunity to alter the default value of a Flag.
Sometimes you may need to alter the default value specified inside the property wrapper signature. This happens if you want to define a single collection file used in several targets of your project where one or more flags have different default values.
In this case you can avoid to replicate the same collection blueprint but just change the default value.

A new call setDefaultValue() is therefore provided to allows this change.

Q A
New Feature yes
BC Break no
@malcommac malcommac added the enhancement New feature or request label Jan 26, 2022
@malcommac malcommac added this to the 1.2.1 milestone Jan 26, 2022
@malcommac malcommac self-assigned this Jan 26, 2022
malcommac added a commit that referenced this issue Jan 26, 2022
@malcommac malcommac mentioned this issue Jan 26, 2022
@malcommac
Copy link
Collaborator Author

Sometimes you may want to alter the default value of a Flag set via the annotation default parameters.
This is true when, for example, you have different target of your product with different values for some flag and you would avoid creating duplicate files for each Flags Collection blue print.

In this case you can define your own FlagsCollections and use the setDefaultValue() on each different flag to setup your own value.

Consider this example:

struct Flags: FlagCollectionProtocol {
    @FlagCollection(default: 100, description: "...")
    var flagA: Int

    @Flag(default: false, description: "...")
    var flagB: Bool
}

public func setupFlagsByTarget {
    self.loader = FlagsLoader(Flags.self, provider: [...])

    #if TARGET_A
      // Target A only differ for a 200 default value for flagA
      loader.$flagA.setDefault(200)
    #endif
    
    #if TARGET_B
      // Target B only differ in flagB which is false by default
      loader.$flagB.setDefault(false)
    #endif
    
    #if TARGET_C
      // Target C has the same false for flagB but a different value for flagA
      loader.$flagA.setDefault(50)
    #endif
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant