Swiftpack.co - BradPatras/brc-ios as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by BradPatras.
BradPatras/brc-ios 0.1.0
Bare-bones remote configs library for iOS
⭐️ 0
🕓 3 weeks ago
iOS
.package(url: "https://github.com/BradPatras/brc-ios.git", from: "0.1.0")

spm version

brc-ios

Bare-bones remote configs for iOS. Check out the basic-remote-configs project repo for more context.

🚧   Under active development   🚧

Swift Package Manager:

Either add it via File -> Add Package or in your Package.swift file:

https://github.com/BradPatras/brc-ios

Usage

The usage is pretty straightforward:

  1. Create an instance of BasicRemoteConfigs
  2. Call .fetchConfigs(). (This is an async function so you'll need to call it with await)
  3. Access your configs.
let configUrl = URL(string: "https://github.com/BradPatras/basic-remote-configs/raw/main/examples/simple.json")!

// #1
let brc = BasicRemoteConfigs(configURL: configUrl)

// ...
try await brc.fetchConfigs() // #2
let someFlag = brc.values["someFlag"] as? Bool // #3

Caching

Configs are stored locally in the app's private storage once they've been fetched from the network. Calling .fetchConfigs() will fetch the locally cached version of configs if either of the following are true:

  1. The cache exists and is not expired (cache expires after one day)
  2. The call to fetch configs from the network failed for any reason.

If you'd like to bypass the cached version and fetch the latest configs from the network, there's an optional param available.

brc.fetchConfigs(ignoreCache: Boolean)

Error handling

The call to .fetchConfigs() may make a network request and do some deserialization, so it's bound to fail at some point. BasicRemoteConfigs will print errors under the key "BasicRemoteConfigs" using Log.e with a hint as to where the error happened in regards to fetching configs. It won't do any handling or masking of the exceptions so you need to wrap it in a try/catch or use a CoroutineExceptionHandler yourself.

do {
    try await brc.fetchConfigs()
} catch {
    // What happens here is up to you
}

GitHub

link
Stars: 0
Last commit: 3 weeks ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Release Notes

0.1.0
3 weeks ago

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