BradPatras / brc-ios

Bare-bones remote configs library for iOS

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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: Bool)

Error handling

The call to .fetchConfigs() may make a network request and do some deserialization, so it's bound to fail at some point. It won't do any handling or masking of the exceptions so you need to wrap it in a do/catch and handle it yourself.

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

About

Bare-bones remote configs library for iOS

License:MIT License


Languages

Language:Swift 100.0%