App environment model generation from project build configurations.
In iOS it provides a feature to show app environment and version info (configurable format) on top of all views. It is effectively "watermarking" all the screenshots the testers might take with relevant version info.
Tool to automatically generate Environment enum based on Xcode project. It will allow you to easily change this:
#if DEBUG
// debug flow
#elseif ALPHA
// alpha flow
#elseif BETA
// beta flow
#else
// release flow
#endifInto:
switch Environment.current {
case .debug:
//debug flow
case .alpha, .beta:
// do something for alpha and beta
case .release:
// only release flow
}That will add a kind of compile-time safety to your code, whenever it is dependent on app environment. There would be only one file where you need to care about conditional compilation. It also allows you to unit test app, pretending to run in specific environment:
Environment.Override.current = .alpha
// test alpha
Environment.Override.current = nil
// back to defaultIt will scan your source and generate file looking like:
enum Environment: String {
case debug = "DEBUG"
case release = "RELEASE"
// other cases derived from configuration
static var current: Environment { ... }
}It will also add OTHER_SWIFT_FLAGS build setting for configurations:
-DDEBUGfor Debug-DRELEASEfor Release-DALPHAfor Alpha- ... and so on
This is a preferred way, as package was explicitly designed to work with Mint. Assuming you have installed mint already, just run:
mint install GirAppe/AutoEnvironmentIf you don't want to link it globally, you can use Mintfile:
GirAppe/AutoEnvironment@0.1.6
Then you can run it:
mint run GirAppe/AutoEnvironment autoenvironment <options>Add package entry to dependecies in your Package.swift:
dependencies: [
.package(url: "https://github.com/GirAppe/AutoEnvironment.git", .upToNextMajor(from: "0.1.6"))
...
]When your target name is same as xcode project filenam:
autoenvironment -p "path to your xcodeproj" -o "output directory/ filename"or
autoenvironment -p "path to your xcodeproj" -o "output directory" <options>Options:
--help,-hShow available options--version,-vPrint tool version--path,-pPath to xcode project--target,-tTarget name. If not specified, will use Project name--output,-oOutput directory (with optional filename.swift)--no-flags,-fSkip update build flags. If flag present, you need to update them manually--default-config,-dDefault configuration (e.x. Release)--default-name,-nGenerated Environment enum name, default: Environment--silent,-sIf flag present, supresses all console logs and prints
For iOS, generated enum contains additional feature to show current app version and environment info label on top of all views.
It will look something like:
Example code to show version info:
if Environment.current != .release {
Environment.info.showVersion()
}You can setup version info:
Environment.info.textAlignment = .left
Environment.info.textColor = .black
Environment.info.shadowColor = .blue
Environment.setVersionFormat(.full)
Environment.setVersionFormat(.simple, for: .release)Version info for tvOS is work in progress.

