Configurate 是一个用于构建分层 Config
对象的包,这些对象本质上是键值集合的堆栈。Configs 是基于协议的,因此它们可以由任何可以为给定键提供值的来源实现。
let config = Config(ProcessInfo.processInfo) // Searches environment variables
.include(UserDefaults.standard) // Searches a UserDefaults instance
.include(try! ConfigFile(url: URL("config.json"))) // Searches a JSON or Plist config file, must result in [String: Any]
.include(["key": "overrideValue"]) // Searches a [String: Any] Dictionary
let value: String? = config["someKey"] // Infers expected return type
包含在 Config
中的键值集合以倒序搜索,以便来自一个集合的值会覆盖先前添加的集合中的值。
import PackageDescription
let package = Package(
name: "MyPackage",
dependencies: [
.Package(url: "https://github.com/patgoley/Configurate.git", majorVersion: 2),
]
)
pod 'Configurate', '~> 2.0'