Skip to content

Instantly share code, notes, and snippets.

@lordcodes
Created November 19, 2018 19:59
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save lordcodes/f9bd45773f1872516bb3e2aaee45cd3f to your computer and use it in GitHub Desktop.
Save lordcodes/f9bd45773f1872516bb3e2aaee45cd3f to your computer and use it in GitHub Desktop.
Read secrets into your iOS project from xcconfig files and then use Sourcery to generate a source file to use them within your code.
#!/bin/bash
# Generate list of arguments to pass to Sourcery
function sourceryArguments {
# Environment variables from BuildConfig to map into AppSecrets
local arguments=(
"CHAT_API_CLIENT_SECRET" "ANALYTICS_WRITE_KEY"
)
local combinedArgs
local argumentsIndices=${!arguments[*]}
for index in $argumentsIndices
do
# Make the arguments list comma-separated
if [ $index -gt 0 ];
then
combinedArgs="${combinedArgs},"
fi
# Append the argument name and escaped argument value
local argument=${arguments[$index]}
local argumentName="${argument}"
local argumentValue="\"${!argument}\""
local argumentPair="${argumentName}=${argumentValue}"
combinedArgs="${combinedArgs}${argumentPair}"
done
echo $combinedArgs
}
sourceryArgs=$(sourceryArguments)
# Generate AppSecrets using the arguments list created above
mkdir -p Generated/Sourcery
Tools/Sourcery/bin/sourcery --sources ChatApp/Sources \
--templates Templates/AppSecrets.stencil \
--output Generated/Sourcery \
--args $sourceryArgs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment