Skip to content

Instantly share code, notes, and snippets.

@kellerkruz
kellerkruz / storyboardUpdate.sh
Last active August 17, 2016 14:10
Storyboard update from constants
storyboard="path-to-storyboard"
constants="path-to-constants-file"
while read -r line || [[ -n "$line" ]]; do
propName=$(echo $line | grep "static let" | sed 's/static let \([^ ]*\): CGFloat =.*$/\1/' | sed 's/\n//g')
propValue=$(echo $line | grep "static let" | sed 's/.*CGFloat = \(.*$\)/\1/' | sed 's/\n//g')
if [ "x$propValue" != "x" ] && [ "x$propName" != "x" ]; then
sed -i '' "s/^\(.*<constraint.*\)constant=\"[^\"]*\" \(.*userLabel=\"${propName}\".*\)$/\1\2/g" $storyboard
sed -i '' "s/^\(.*<constraint.*\)\(id=\"[^\"]*\".*userLabel=\"${propName}\".*\)$/\1constant=\"${propValue}\" \2/g" $storyboard
fi