ConfigLoader

public enum ConfigLoader

A helper to load a configuration plist file and mapping it to its model. The config file should contain all necessary data to run the app, e.g. server URLs, token IDs, etc. The config has to match the corresponding Configuration model.

  • The name of the config plist file in the bundle, equals to Config.plist.

    Declaration

    Swift

    public static let ConfigName: String
  • The errors which might occur during parsing a config file.

    See more

    Declaration

    Swift

    public enum Error : Swift.Error
  • Parses the config file into its model.

    Specify the name of the config file and the bundle where to find it. Then provide the model’s type as the result into which the method should try to decode the file’s content into.

    guard case let .success(config) = ConfigLoader.parseConfig() as Result<MyConfigModel, ConfigLoader.Error> else {
    return
    }
    

    Declaration

    Swift

    public static func parseConfig<Configuration>(
    	named fileName: String = ConfigName,
    	bundle: Bundle = Bundle.main
    ) -> Result<Configuration, Error> where Configuration: Decodable

    Parameters

    fileName

    The property list’s file name which will be decoded. Defaults to ConfigName.

    bundle

    The bundle from which to load the config file. Defaults to the main bundle.

    Return Value

    A Result instance with either the decoded model or the error.