TPFeatureTag
Swift 项目的简单功能标签管理
用法
定义您的功能标签
// 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
每个返回的功能包含以下内容
name
由变量名生成的反射namespace
由包含类生成的反射key
由makeFeature
分配isOn
特定功能标签从最高优先级解析器返回值时的当前解析状态source
返回值的解析器名称,如果没有解析器返回值则使用makeFeature
默认值default
安装
TPFeatureTag 通过 CocoaPods 提供。要安装它,只需将以下行添加到您的 Podfile 中
pod 'TPFeatureTag'
作者
Eliran Ben-Ezra, [email protected]
许可
TPFeatureTag 可在 MIT 许可下使用。有关更多信息,请参阅 LICENSE 文件。