TPFeatureTag
Simple feature tags managment for swift projects
Usage
Define your feature tags
// 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()Check if a feature is enabled or not
...
if features.feature1.isOn {
// Code to execute if feature is enabled
} else {
// Code to execute if feature is disabled
}
...Install resolver(s)
...
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
...
FeatureTags.Manager.install(name: 'local', priority: 10, resolver: FeatureTags.Resolvers.Local(namespace: 'featuretags'))
...
}Update feature tags state in a specific resolver
// 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')Update feature tags state for all resolvers
// 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)Get a list of registered feature tags
let allFeatures = FeatureTags.Manager.instance.allFeaturesEach feature returned contains:
namegenerated by reflection from the variable namenamespacegenerated by reflection from the containing classkeyassigned bymakeFeatureisOncurrent resolved state of the feature from the highest priority resolver that returned a value to that feature tagsourcethe resolver's name that returned the valuedefaultif no resolver returns a value and using themakeFeaturedefault
Installation
TPFeatureTag is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'TPFeatureTag'Author
Eliran Ben-Ezra, [email protected]
License
TPFeatureTag is available under the MIT license. See the LICENSE file for more info.