Swiftpack.co - michaelhenry/XConfigs as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by michaelhenry.
michaelhenry/XConfigs 1.1.0
🛠Configs, a quick, simple and stylish solution for your remote and dev configurations.
⭐️ 4
🕓 39 weeks ago
.package(url: "https://github.com/michaelhenry/XConfigs.git", from: "1.1.0")


A quick, simple and stylish solution for your remote and dev configurations.

codecov test release Swift5.7 Platform Support license


As part of software development process, we always need to see how our app will react depending on the different scenarios or configurations especially during testing. At the same time, it would be better if we can control some of app configurations on the fly, especially if there are unexpected things happened in our production environment, we can immediately enable or disable certain app functionality.

Getting Started

Install using SPM

.package(url: "https://github.com/michaelhenry/XConfigs", .upToNextMinor(from: "1.0.0")),

How to use

let kvProvider = SampleKeyValueProvider()

// Register the AppConfigs and set which keyValueProvider and option to use. Note that `.allowInAppModification(InAppModificationOption)` option accepts a `KeyValueStore`.
XConfigs.configure(with: AppConfigs.self, keyValueProvider: kvProvider, option: .allowInAppModification(.init(store: UserDefaults.standard)))

Please note that on production build, it is recommend that the in-app modification is disabled (option is set to readonly), so XConfigs will just use either the value from the keyValueProvider or the default value assigned inside the property wrapper as fallback.


    XConfigs.configure(with: MockConfigs.self, keyValueProvider: kvProvider, option: .allowInAppModification(.init(store: UserDefaults.standard)))
    XConfigs.configure(with: MockConfigs.self, keyValueProvider: kvProvider, option: .readonly)

📄 Documentation

Please refer to XConfigs's docs.


Similar with logger tool such as swift-log, You can simply create a single global variable or just a singleton, as long as the it conforms to XConfigSpecification and then use the @XConfig property wrapper inside it.

If you have some custom datatype, you can simply conform them to RawStringValueRepresentable. So the key thing is as long as a value can be represented as a string, it should be fine.

struct AppConfigs: XConfigSpec {

    @XConfig(key: "isOnboardingEnabled", defaultValue: false)
    var isOnboardingEnabled: Bool

    @XConfig(key: "apiURL", defaultValue: URL(string: "https://google.com")!)
    var apiURL: URL

    @XConfig(key: "region", defaultValue: .north)
    var region: Region

    @XConfig(key: "maxRetry", defaultValue: 10)
    var maxRetry: Int

    @XConfig(key: "threshold", defaultValue: 1)
    var threshold: Int

    @XConfig(key: "rate", defaultValue: 2.5)
    var rate: Double

enum Region: String, CaseIterable, RawStringValueRepresentable {
    case north
    case south
    case east
    case west

For the complete example, please refer to the Demo project which auto-generated the screen(below) using the AppConfigs.swift config specification.



Other Related

Firebase Remote Config

You can backed XConfigs by FirebaseRemoteConfig by simply implementing the KeyValueProvider protocol.


import FirebaseRemoteConfig

struct FirebaseKeyValueProvider: KeyValueProvider {

    private let remoteConfig: RemoteConfig = {
        let rconfig = RemoteConfig.remoteConfig()
        let settings = RemoteConfigSettings()
        settings.minimumFetchInterval = 0
        rconfig.configSettings = settings
        return rconfig
    // Please refer to https://firebase.google.com/docs/remote-config/get-started?platform=ios
    func fetch() {
        remoteConfig.fetch { (status, error) -> Void in
            if status == .success {
                print("Config fetched!")
                self.remoteConfig.activate { changed, error in
                    // ...
            } else {
                print("Config not fetched")
                print("Error: \(error?.localizedDescription ?? "No error available.")")

    // XConfigs KeyValueProvider protocol
    func get<Value>(for key: String) -> Value? where Value : RawStringValueRepresentable {
        guard let rawValue = remoteConfig.configValue(forKey: key).stringValue, let value = Value(rawString: rawValue) else { return nil }
        return value




Stars: 4
Last commit: 25 minutes ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Release Notes

39 weeks ago

What’s Changed

  • [Chore] Update minimum supported iOS version to 14 (#41) @michaelhenry

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics