A pre-build (Swift) script to alter your Xcode project at build-time per environment and build configuration.
TL;DR
With Natrium you can change this:
#if ENVIRONMENT_STAGING
let apiHost = "mynice.staging-api.com"
#elseif ENVIRONMENT_DEVELOPMENT
let apiHost = "mynice.dev-api.com"
#else
let apiHost = "mynice.api.com"
#endif
Alamofire.request("https://\(apiHost)/items").responseJSON { response in
// ...
}
Into this:
let apiHost = Natrium.Config.apiHost
Alamofire.request("https://\(apiHost)/items").responseJSON { response in
// ...
}
🧙♂️ With the magic of pre-action run scripts. 😱
"${PROJECT_DIR}/Pods/Natrium/Natrium/natrium" Production
Migration
To v8.x
The location of the binary is changed from (for instance in Cocoapods) Pods/Natrium/bin/natrium to Pods/Natrium/Natrium/natrium
The location of the generated Natrium.swift is changed to (for instance in Cocoapods): Pods/Natrium/Natrium/Natrium.swift
To v7.x
natrium install is removed
Both .natrium-env and .env files can be used for environment variables
CLI no longer needs --project argument
No longer supports Objective-c, use v6.4.0 if you still need it.
To v6.x
For Natrium v6.x you need to manually import the Natrium.swift file to your project to make it work in the new xcode build system. Read the Installation guide.
From v5.x
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.2 compatible
Use swift instead of ruby
Remove ImageMagick dependency
Unit tests
Different installation options (apart from CocoaPods)
In the Pods/Natrium/bin/ folder you can find natrium.log with the logs of the previous build. It might help you with debugging.
Environment variables
If you place .env in the root of your project. Natrium will use that fill to add environment variables to your already existing environment variables.
The .env file should have to following format:
Natrium is part of the E-sites iOS Suite.
A pre-build (Swift) script to alter your Xcode project at build-time per environment and build configuration.
TL;DR
With Natrium you can change this:
Into this:
🧙♂️ With the magic of pre-action run scripts. 😱
Migration
To v8.x
Pods/Natrium/bin/natrium
toPods/Natrium/Natrium/natrium
Pods/Natrium/Natrium/Natrium.swift
To v7.x
natrium install
is removed.natrium-env
and.env
files can be used for environment variables--project
argumentTo v6.x
For Natrium v6.x you need to manually import the
Natrium.swift
file to your project to make it work in the new xcode build system. Read the Installation guide.From v5.x
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
Installation
Implementation
Swift
Just add
Natrium.swift
(from the designated location, see installation guide) to your project’s target (do not copy).Configuration
Configuration documentation can be found here.
Usage
The example
.natrium.yml
as shown above, will result in the following Config.swift file:It can be used like so:
Result:
Development
Run
and open
Natrium.xcodeproj
Advanced
Logging
In the
Pods/Natrium/bin/
folder you can findnatrium.log
with the logs of the previous build. It might help you with debugging.Environment variables
If you place
.env
in the root of your project. Natrium will use that fill to add environment variables to your already existing environment variables. The.env
file should have to following format:for instance:
This way you can use
#env(PRODUCTION_SECRET_API_TOKEN)
in your.natrium.yml
file.For CI/CD pipelines you can simply add those environment variables to your build pipeline (in travis or buddybuild for instance).
But if you want to use it for local (debug) builds, this file can be helpful.
⚠️ Don’t forget to add
.env
to your.gitignore