Home

Awesome

<p align="center"> <picture> <source media="(prefers-color-scheme: dark)" srcset="./documentation/assets/realflags-dark.png" width="350"> <img alt="logo-library" src="./documentation/assets/realflags-light.png" width="350"> </picture> </p>

RealFlags makes it easy to configure feature flagsin your codebase. It's designed for Swift and provides a simple and elegant abstraction layer over multiple providers you can query with your priority. It also has a handy UI tool to browse and alter values directly at runtime!

<br/> <p align="center"> <b><a href="#features-highlights">Features</a></b> | <b><a href="#what-you-get">What You Get</a></b> | <b><a href="#flags-browser--editor">Flags Browser & Editor</a></b> | <b><a href="#tests">Tests</a></b> | <b><a href="#documentation">Documentation</a></b> | <b><a href="#requirements">Requirements</a></b> | <b><a href="#installation">Installation</a></b> | <b><a href="#powered-apps">Powered Apps</a></b> | <b><a href="#support">Support & Contribute</a></b> | <b><a href="#license">License</a></b> </p> <br/>

Features Highlights

An Hands-on Approach

Would you use RealFlags in your product? We wrote an article about it. Check it out here

What You Get

Our goal in making RealFlags is to provide a type-safe abstract way to describe and query for feature flags.

The first step is to describe your collection of flags:

// Define the structure of your feature flags with type-safe properties!
struct UserFlags: FlagCollectionProtocol {
 @Flag(default: true, description: "Show social login options along native login form")
 var showSocialLogin: Bool
 
 @Flag(default: 0, description: "Maximum login attempts before blocking account")
 var maxLoginAttempts: Int
 
 @Flag(key: "rating_mode", default: "at_launch", description: "The behaviour to show the rating popup")
 var appReviewRating: String

 public init() {}
}

This represents a type-safe description of some flags grouped in a collection. Each feature flags property is identified by the @Flag annotation. It's time load values for this collection; using a new FlagsLoader you will be able to load and query collection's values from one or more data providers:

// Allocate your own data providers
let localProvider = LocalProvider(localURL: fileURL)
let fbProvider = FirebaseRemoteProvider()

// Loader is the point for query values
let userFlagsLoader = FlagsLoader(UserFlags.self, // load flags definition
 description: .init(name: "User Features", description: "Cool experimental features for user account"),
 providers: [fbProvider, localProvider]) // set providers

Now you can query values from userFlagsLoader by using the UserFlags structure (it supports autocomplete and type-safe values thanks to @dynamicMemberLookup!). Let me show it:

if userFlagsLoader.showSocialLogin { // query properties as type-safe with autocomplete!
 // do some stuff
}

Values are obtained respecting the order you have specified, in this case from Firebase Remote Config service, then, when no value is found, into the local repository. If no values are available, the default value specified in @Flags annotation is returned.

This is just an overview of the library; if you want to know more, follow the documentation below.

Flags Browser & Editor

RealFlags also comes with a handy tool you can use to browse and edit feature flag values directly in your client! It can be helpful for testing purposes or allow product owners to enable/disable and verify features of the app.

Checkout the doc for more infos!

https://user-images.githubusercontent.com/235645/150638946-99646e96-d155-451f-a723-585ad7978c43.mp4

API Reference

RealFlags is fully documented at the source-code level. You'll get autocomplete with doc inside XCode for free; moreover, you can read the full Apple's DoCC Documentation automatically generated thanks to Swift Package Index Project from here:

👉 API REFERENCE

Documentation

The following documentation describes detailed usage of the library.

Test Suite

RealFlags includes an extensive collection of unit tests: you can find it in the Tests directory.

Requirements

RealFlags can be installed on any platform which supports Swift 5.4+, including Windows and Linux. On Apple platform, the following configuration is required:

Installation

To use RealFlags in your project you can use Swift Package Manager (our primary choice) or CocoaPods.

Swift Package Manager

Add it as a dependency in a Swift Package, and add it to your Package.swift:

dependencies: [
 .package(url: "https://github.com/immobiliare/RealFlags.git", from: "1.0.0")
]

And add it as a dependency of your target:

targets: [
 .target(name: "MyTarget", dependencies: [
 .product(name: "https://github.com/immobiliare/RealFlags.git", package: "RealFlags")
 ])
]

In Xcode 11+, you can also navigate to the File menu and choose Swift Packages -> Add Package Dependency..., then enter the repository URL and version details.

CocoaPods

RealFlags can be installed with CocoaPods by adding pod 'RealFlags' to your Podfile.

pod 'RealFlags' // to import the core framework
pod 'RealFlagsFirebase' // to also import Firebase Data Provider

Powered Apps

The amazing mobile team at ImmobiliareLabs created RealFlags, the Tech dept at Immobiliare.it, the first real estate site in Italy. We are currently using RealFlags in all of our products.

If you are using RealFlags in your app drop us a message.

Support

<a href="http://labs.immobiliare.it"><img src="./documentation/assets/immobiliarelabs.png" alt="ImmobiliareLabs" width="200"/></a>

We'd love for you to contribute to RealFlags! If you have questions about using RealFlags, bugs, and enhancement, please feel free to reach out by opening a GitHub Issue.

License

RealFlags is licensed under the MIT license. See the LICENSE file for more information.