FeatherQuill

轻松地将新功能推广给您的部分受众。

SwiftPM Twitter GitHub GitHub issues GitHub Workflow Status

Codecov CodeFactor Grade codebeat badge Code Climate maintainability Code Climate technical debt Code Climate issues Reviewed by Hound

功能

FeatherQuill 是一个 Swift 包,它提供了一种在您的应用程序中实现离线功能标志的机制。 功能标志允许您为不同的用户或用户群启用或禁用功能,而无需服务器端更新。 这对于 A/B 测试、推广策略等非常有用。

要求

Apple 平台

Linux

安装

要将 FeatherQuill 包添加到您的 Xcode 项目,请选择 “File” > “Swift Packages” > “Add Package Dependency”,然后输入存储库 URL。

使用 Swift Package Manager 添加存储库 URL

dependencies: [
  .package(url: "https://github.com/brightdigit/FeatherQuill", from: "1.0.0-alpha.1")
]

用法

FeatherQuill 利用协议和泛型来实现灵活且类型安全的体验。 这是一个关于如何定义和使用功能的简化示例

// Define a user type (e.g., user roles)
public enum UserRole: UserType {
  case free
  case pro
  case admin

  public static var `default`: UserRole {
    return .free
  }
}

// Define a feature with a default value and targeting
struct MyFeature: FeatureFlag {
  static var audience: UserRole { .pro }
  static var probability: Double { 0.2 } // 20% chance of being enabled
  static var initialValue: Bool { false }
  static var options: AvailabilityOptions { .default }

  @Sendable
  static func evaluateUser(_ userType: UserRole) async -> Bool {
    // Optional: Implement custom user evaluation logic here
    return true
  }
}

extension EnvironmentValues {
  public var newDesignFeature: MyFeature.Feature { self[MyFeature.self] }
}

// Accessing the feature in a SwiftUI view
struct MyView: View {
  @Environment(\.myFeature) var myFeature

  var body: some View {
    if myFeature.isAvailable {
      Toggle("Is Enabled", isOn: myFeature.bindingValue)
    } else {
      Text("This feature is disabled.")
    }
  }
}

许可证

FeatherQuill 在 MIT 许可证下可用。 有关更多信息,请参见 LICENSE 文件。