Giter Site home page Giter Site logo

featureflagscontroller-ios's Introduction

FeatureFlagsController

pod

FeatureFlagsController is a micro-library to automatically build a SwiftUI Form View from all registered feature flags in a project, leveraging power of functional reactive programming using Combine.

Requirements

  • iOS 13.0+
  • Xcode 12.0+
  • Swift 5.2+

Installation

CocoaPods

Add the following to your Podfile:

pod "FeatureFlagsController"

Swift Package Manager

https://github.com/DataDog/FeatureFlagsController using Xcode 12 SPM integration

Usage

FeatureFlagsView

All registered feature flags appear in a FeatureFlagsView which is a SwiftUI.View composed of a NavigationView and a sectionned Form. You can display this view anywhere in your application. In a hidden "debug" menu for example.

This form keeps track of registered feature flags and display the right UI to modify them at runtime. A ToggleFeatureFlag will display a simple Toggle (UISwitch) while a PickerFeatureFlag will display a segmented control or a sub-menu depending the picker style it is given.

Declaration

Here is how you declare a new Feature Flag:

let roundedCornersFeatureFlag = ToggleFeatureFlag(
    title: "Rounded Corners", defaultValue: true, group: "Home Screen"
)

Declaring a feature flag doesn't do anything on its own, but you still can access its value using the value property. Some feature flags types have an alias to the value property to make the call-site more clear. For example, the ToggleFeatureFlag has the isEnabled alias.

Registration

In order to display a feature flag in the FeatureFlagsView, a feature flag must be registered. The register() methods return a Combine AnyPublisher<Value, Never> emitting immediately the current value, then all value updates.

Once the Combine subscription is cancelled (for example, when the owning view controller is popped or dismissed), the feature flag disappears from the FeatureFlagsView.

roundedCornersFeatureFlag
    .register() // Adds the feature flag to the `FeatureFlagsView` and returns an AnyPublisher<Bool, Never>
    .map { $0 ? 16 : 0 } // Use all Combine operators you want to
    .assign(to: \.cornerRadius, on: squareView.layer) 
    .store(in: &cancellables) // On cancellation, the feature flag is removed from the `FeatureFlagsView`

License

This framework is provided under the MIT license.

featureflagscontroller-ios's People

Contributors

jegnux avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.