A pre-build ruby script to alter your Xcode project at build time per environment and build configuration. (swift only)
Add the following to your Podfile
:
pod 'Natrium'
Run pod install
or pod update
Create build-config.yml
in the root of your project (in the same folder as the .xcproject and .xcworkspace files).
Check the configuration parameters here.
Create a Pre-Action per scheme which runs the following script:
/bin/sh "${PROJECT_DIR}/Pods/Natrium/Natrium/script.sh" Staging
The final argument "Staging"
is the actual environment you want to use for that specific scheme.
This way you can create different schemes per environment
Provide build settings from...
selectbox
Add it to your project
// AppDelegate.swift
import Natrium
let Config = Natrium.Config
This step is also optional, but this way you can use the Config
class through your entire project without having to use the import Natrium
statement in every class.
environments:
- Staging
- Production
natrium_variables:
DeeplinkUrlSchemeName:
Staging: "natriumexample_staging"
Production: "natriumexample"
infoplist:
CFBundleDisplayName:
Staging: App_staging
Production: App
xcconfig:
PRODUCT_BUNDLE_IDENTIFIER:
Staging: com.esites.app.staging
Production:
Adhoc,Debug: com.esites.app.production
Release: com.esites.app
DEEPLINK_URL_SCHEME: "#{DeeplinkUrlSchemeName}"
variables:
testVariableDouble:
Staging: 1.1
Production: 5.5
testVariableString:
Staging,Production:
Debug: "debugString"
Adhoc: "adhocString"
Release: "releaseString"
testVariableBoolean: false
testVariableInteger: 125
deeplinkUrlSchemeName: "#{DeeplinkUrlSchemeName}"
files:
Firebase/GoogleService-Info.plist:
Dev: Firebase/GoogleService-Info_DEV.plist
Staging: Firebase/GoogleService-Info_STAGING.plist
Production: Firebase/GoogleService-Info_PRODUCTION.plist
appicon:
original: icon.png
appiconset: NatriumExampleProject/Assets.xcassets/AppIcon.appiconset/
ribbon:
Production: ""
Staging: "STAGING"
target_specific:
NatriumExampleProject2:
variables:
testVariableString: "Target #2"
infoplist:
CFBundleDisplayName: "App #2"
misc:
launchScreenStoryboard:
path: NatriumExampleProject/Base.lproj/LaunchScreen.storyboard
labelName: LaunchScreenVersionLabel
enabled:
Dev,Staging: true
Production: false
Key | Type | Description |
---|---|---|
environments | Array | Which environments does your project support |
natrium_variables | Dictionary* | Use variables within the yml file. In this build config file "#{value_name} " will be replaced with the corresponding value. |
infoplist | Dictionary* | Keys of the Info.plist to be changed per environment / configuration. Instead of the infoplist directive, you can also use a relative path to the .plist file location. |
xcconfig | Dictionary* | Build settings per environment / configuration |
variables | Dictionary* | Custom variables per environment / configuration (written in Config.swift) |
files | Dictionary* | Overwrite a specific file per environment / configuration. Relative to path the project directory. |
appicon | App-Icon | Place a ribbon on your app-icon |
target_specific | Dictionary | Target specific values. The first key of this dictionary is the target name, the value of that dictionary is the same as the values shown above (infoplist , xcconfig , variables , files , appicon ). This way you can make target specific modifications per build. |
misc | Miscellaneous | Miscellaneous settings |
- See the Xcode Build Settings Reference
- Checkout the platform specific Property list keys
- Use the online YAML validator to validate your build-config.yml
- All the dictionaries support different types of notations:
-
Every environment / configuration will use that
value
:key: value
-
Differrent values per environment
key: Staging: value1 Production: value2
-
Differrent values per environment and configuration
key: Staging: Debug: stagingDebugValue Release: stagingReleaseValue Production: Debug: productionDebugValue Release: productionReleaseValue
-
Differrent values per configuration
key: Staging,Production: Debug: debugValue Release: releaseValue
The app-icon
setting has 3 options:
original
: The relative path (according to your project) of the original icon file (minimum of 180x180px). Which can be used to put the ribbon onappiconset
: The relative path (according to your project) of theAppIcon.appiconset
folder, to store the icons inribbon
: The text that should be placed in the ribbon. An empty string (""
) would remove the ribbon
This script searches for images in the appiconset
directory and then puts a badge on every single one of them. So to make sure this works, the appiconset
should contain images (pngs)
Alter a UILabel
in the LaunchScreen storyboard to show the current app version.
Arguments:
Key | Type | Description |
---|---|---|
path | String * | Relative path to the LaunchScreen.storyboard file |
labelName | String * | The accessability label value of the UILabel in that storyboard |
enabled | Boolean * | Disabling this will empty the UILabel |
The example build-config.yml
as shown above, will result in the following Config.swift file:
import Foundation
public class Config {
public enum EnvironmentType : String {
case staging = "Staging"
case production = "Production"
}
public enum ConfigurationType : String {
case release = "Release"
case adhoc = "Adhoc"
case debug = "Debug"
}
public static let environment:EnvironmentType = .staging
public static let configuration:ConfigurationType = .debug
public static let testVariableDouble:Double = 1.1
public static let testVariableString:String = "debugString"
public static let testVariableBoolean:Bool = false
public static let testVariableInteger:Int = 125
public static let deeplinkUrlSchemeName:String = "natriumexample_staging"
}
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: Optional("com.esites.app.staging")
environment: staging