Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save saroar/b47cf3e1f074b0ba9b2045359eca53e2 to your computer and use it in GitHub Desktop.
Save saroar/b47cf3e1f074b0ba9b2045359eca53e2 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