Kiryl Famin
Kiryl Famin

Reputation: 337

How to allow application-level overrides for a configuration system used within a Core library in an iOS app?

We have a Core library that provides shared logic across our iOS app. Inside this library, we use an enum as a configuration container, storing various static properties (mainly closures).

The entities inside the Core library access these configurations to determine behavior. However, we need a way to allow the app to override these settings at runtime without modifying the Core library itself.

Example:

Current setup in Core library

enum Config {
    static var loader: () -> LoaderProtocol = { DefaultLoader() }
}

How the Core library uses it

class SomeCoreController {

    func showLoader() {
        let loader = Config.loader()
        loader.start()
    }
}

Overriding in the main app

Config.loader = { CustomLoader() }

The problem

The enum is getting cluttered with many unrelated settings.

What I’m looking for:

  1. A way for organizing such a configuration system.

  2. A clean way to allow overriding behavior at the application level

Upvotes: 0

Views: 19

Answers (0)

Related Questions