A pre-build (Swift) script to alter your Xcode project at build-time per environment and build configuration.
Swift Ruby Other
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
Assets
Example
Res
Sources
bin
docs
.gitignore
.swift-version
.swiftlint.yml
.travis.yml
CHANGELOG.md
LICENSE
Makefile
Natrium.podspec
Package.resolved
Package.swift
README.md
get_version.sh

README.md

Natrium

A pre-build (Swift) script to alter your Xcode project at build-time per environment and build configuration.

forthebadge forthebadge

Platform CocoaPods Compatible Quality Carthage compatible Travis-ci

⚠️ IMPORTANT
Natrium v5.x doesn't need a build phase script anymore.
Open your Build Phases from your target settings and remove the [Natrium] check step.

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

Implementation

If you installed it from cocoapods:

// AppDelegate.swift

import Natrium
typealias Config = Natrium.Config

This 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

Termin

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.