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

load(configuration:named:from:linkingAgainst:in:at:minimumMacOSVersion:reportProgress:)

where C : Configuration, L : InputLocalization

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

Declaration

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

Discussion

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 // https://github.com/SDGGiesbrecht/SDGCornerstone, 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: // https://github.com/SDGGiesbrecht/SDGSwift/tree/0.6.0/Sources/SampleConfiguration let product = "SampleConfiguration" let package = Package(url: URL(string: "https://github.com/SDGGiesbrecht/SDGSwift")!) 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")

Parameters

configuration

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

fileName

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.)

directory

The directory in which to look for a configuration.

product

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).

package

The package were the module is defined.

releaseVersion

The version of the package to link against.

minimumMacOSVersion

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

reportProgress

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

progressReport

A line of output.

Returns

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

Linux macOS