ConfigurationPlist is renamed to BuildConfig.swift, and this repository will be EOL.
See https://github.com/417-72KI/BuildConfig.swift
ConfigurationPlist is a tool to generate configuration files by merging yamls or jsons.
By splitting the file for each type of setting, it is possible to prevent conflicts of configuration files.
Also, by splitting the file for environment configurations, it will be easier to overwrite configurations for each environment.
{
"API": {
"domain": "http://localhost",
"path": {
"login": {
"method": "POST",
"path": "/login"
},
"getList": {
"method": "GET",
"path": "/list"
}
}
}
}
let file = Bundle.main.path(forResource: "Base", ofType: "json")!
let data = try! Data(contentsOf: URL(fileURLWithPath: filePath))
let config = try! JSONSerialization.jsonObject(with: data, options: []) as! [String: Any]
let api = config["API"] as! [String: Any]
let domain = api.domain as! String // "http://localhost"
let loginPath = (api.path as! [String: Any])["login"] as! [String: Any]
let path = loginPath.path // "/login"
let method = loginPath.method // "POST"
let config = AppConfig.default
let domain = config.API.domain // "http://localhost"
let path = config.API.path.login.path // "/login"
let method = config.API.path.login.method // "POST"
$PROJECT/Resources/Config
..env
into above directory.pod 'ConfigurationPlist'
Run script
build phase to your test target's Build Phases
:if [ "${CONFIGURATION}" = 'Release' ]; then
ENVIRONMENT='production'
else
ENVIRONMENT='staging'
fi
"${PODS_ROOT}/ConfigurationPlist/configurationPlist" -e $ENVIRONMENT "$SRCROOT/$PROJECT/Resources/Config"
You can replace "$SRCROOT/$PROJECT/Resources/Config"
to the relative path from project to the directory you created.
Also, you can add -o
option with output path to specify where Config.plist
and AppConfig.generated.swift
will be created.
Add $(TEMP_DIR)/configurationplist-lastrun
into Input Files
in above Run script
build phase.
Add $(SRCROOT)/Config.plist
and $(SRCROOT)/AppConfig.generated.swift
into Output Files
in above Run script
build phase.
-o
option, you have to change Output Files
to those paths.Drag the new Run Script
phase above the Compile Sources
phase and below Check Pods Manifest.lock
If you are using R.swift, drag the new Run Script
above the Run Script
phase for R.swift and you can load with R.file.configPlist
.
Build your project, in Finder you will now see a Config.plist
and AppConfig.generated.swift
in $SRCROOT
or a path you set with -o
option in above Run script
build phase.
Drag them into your project.
Tip: Add the Config.plist
pattern and the *.generated.swift
pattern to your .gitignore
file to prevent unnecessary conflicts.
TODO: Future support.
ConfigurationPlist
doing?$SRCROOT/$PROJECT/Resources/Config
, exclude .env
.-e
option is set and a file with the same name as that option exists in $SRCROOT/$PROJECT/Resources/Config/.env
, only that file is read.-e staging
option means to read $SRCROOT/$PROJECT/Resources/Config/.env/staging.{yml/yaml/json}
.Swift.Dictionary
.Available under the MIT License.
link |
Stars: 2 |
Last commit: 4 years ago |
Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics