A pre-build (Swift) script to alter your Xcode project at build-time per environment and build configuration.
⚠️ IMPORTANT
Natrium v5.x doesn't need a build phase script anymore.
Open yourBuild Phasesfrom your target settings and remove the[Natrium] checkstep.Else your build will fail during the script steps
Roadmap
- Swift 4.0 compatible
- Use swift instead of ruby
- Remove ImageMagick dependency
- Unit tests
- Different installation options (apart from CocoaPods)
- Better error handling / reporting
Installation
- CocoaPods → Read the instructions here.
- Carthage → Read the instructions here.
- Manually → Read the instructions here.
Implementation
If you installed it from cocoapods:
// AppDelegate.swift
import Natrium
typealias Config = Natrium.ConfigThis step is optional, but this way you can use the Config class through your entire project without having to use the import Natrium statement in every seperate class.
You can now use the Config.swift file and its underlying class.
Configuration
Configuration documentation can be found here.
Usage
The example .natrium.yml as shown above, will result in the following Config.swift file:
import Foundation
/// Natrium.Config
/// Autogenerated by natrium
///
/// - see: https://github.com/e-sites/Natrium
public class Config {
public enum EnvironmentType: String {
case staging = "Staging"
case production = "Production"
}
public enum ConfigurationType: String {
case debug = "Debug"
case release = "Release"
}
public static let environment: EnvironmentType = .staging
public static let configuration: ConfigurationType = .debug
// swiftlint:disable line_length
public static let testVariableDouble: Double = 1.0
public static let testVariableString: String = "debugString"
public static let testVariableBoolean: Bool = false
public static let testVariableInteger: Int = 125
// swiftlint:enable line_length
}It can be used like so:
class MainViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
print("bundle identifier: \(Bundle.main.bundleIdentifier!)")
print("environment: \(Config.environment)")
}
}Result:
bundle identifier: com.esites.app.staging
environment: staging
Advanced
Re-install
To re-run the previous natrium command with the stored arguments from the Natrium.lock file:
./natrium install
Logging
In the Pods/Natrium/bin/ folder you can find natrium.log with the logs of the previous build. It might help you with debugging.

Formed in 2009, the Archive Team (not to be confused with the archive.org Archive-It Team) is a rogue archivist collective dedicated to saving copies of rapidly dying or deleted websites for the sake of history and digital heritage. The group is 100% composed of volunteers and interested parties, and has expanded into a large amount of related projects for saving online and digital history.


