import SDGSwiftConfigurationLoading .product(name: "SDGSwiftConfigurationLoading", package: "SDGSwift")
Type Method


where C : Configuration, L : InputLocalization

Loads the configuration in the specified directory with the specified file name.


class func load<C, L>(configuration: C.Type, named fileName: UserFacing<StrictString, L>, from directory: URL, linkingAgainst product: String, in package: Package, at releaseVersion: Version, minimumMacOSVersion: Version, reportProgress: (_ progressReport: String) -> Void = default) -> Result<C, Configuration.Error> where C : Configuration, L : InputLocalization


A loadable file might look something like this:

// Import the configuration definitions. import SampleConfiguration /* Exernal packages can be imported with this syntax: import [module] // [url], [version], [product] */ import SDGControlFlow //, 2.5.0, SDGControlFlow // Initialize the configuration with its defaults. let configuration = SampleConfiguration() // Change whatever options are available. configuration.option = "Configured" // The configuration loader may provide context information. assert(SampleContext.context?.information == "Information")

The above file could be loaded like this:

// These refer to a real, working sample product. // See its source for more details: // let product = "SampleConfiguration" let package = Package(url: URL(string: "")!) let minimumMacOSVersion = Version(10, 13) let version = Version(0, 12, 7) let type = SampleConfiguration.self // Import it first if necessary. // Assuming the above file is called “SampleConfigurationFile.swift”... let name = UserFacing<StrictString, APILocalization>( { _ in return "SampleConfigurationFile" } ) // Change this to actually point at a directory containing the above file. let configuredDirectory: URL = wherever // Context information can be provided. (Optional.) let context = SampleContext(information: "Information") // A log to collect progress reports while loading. (Optional.) var log = String() let loadedConfiguration = try SampleConfiguration.load( configuration: type, named: name, from: configuredDirectory, linkingAgainst: product, in: package, at: version, minimumMacOSVersion: minimumMacOSVersion, context: context, reportProgress: { print($0, to: &log) } ).get() XCTAssertEqual(loadedConfiguration.option, "Configured")



The subclass of Configuration to load. (This is equivalent to the package manager’s Package type.


The localized file name (without “.swift”) of the configuration. Any of the localized names will be detected. If several are present, which one gets loaded is undefined. (This file name is equivalent to the package manager’s Package.swift.)


The directory in which to look for a configuration.


The name of the product which defines the Configuration subclass. Users will directly import it in configuration files. (This is equivalent to the package manager’s PackageDescription module).


The package were the module is defined.


The version of the package to link against.


The minimum version of macOS required by the package. This restriction must be narrower than any indirectly imported package.


Optional. A closure to execute for each line of compiler output.


A line of output.


The loaded configuration if one is present, otherwise the default configuration.

Linux macOS