Simple feature tags managment for swift projects
// Subclass FeatureTags to get automatic feature registration
class Features: FeatureTags {
let feature1 = makeFeature()
let feature2 = makeFeature(key: "remote_feature1", enabled: true)
}
// Singleton instance for features
let features = Features()
...
if features.feature1.isOn {
// Code to execute if feature is enabled
} else {
// Code to execute if feature is disabled
}
...
...
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
...
FeatureTags.Manager.install(name: 'local', priority: 10, resolver: FeatureTags.Resolvers.Local(namespace: 'featuretags'))
...
}
// Set a value if resolver supports it (ignored if setting is not supported)
FeatureTags.Manager.instance.set(features.feature1, to: true, in: 'local')
// Remove a value and allow an higher priority resolver to resolve a value
FeatureTags.Manager.instance.remove(features.feature1, from: 'local')
// Set a value if resolver supports it (ignored if setting is not supported)
FeatureTags.Manager.instance.set(features.feature1, to: true)
// Remove a value and allow an higher priority resolver to resolve a value
FeatureTags.Manager.instance.remove(features.feature1)
let allFeatures = FeatureTags.Manager.instance.allFeatures
Each feature returned contains:
name
generated by reflection from the variable namenamespace
generated by reflection from the containing classkey
assigned bymakeFeature
isOn
current resolved state of the feature from the highest priority resolver that returned a value to that feature tagsource
the resolver's name that returned the valuedefault
if no resolver returns a value and using themakeFeature
default
TPFeatureTag is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'TPFeatureTag'
Eliran Ben-Ezra, eliran@threeplay.com
TPFeatureTag is available under the MIT license. See the LICENSE file for more info.