Skip to content

Instantly share code, notes, and snippets.

@tapi
Created July 31, 2013 22:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tapi/6126598 to your computer and use it in GitHub Desktop.
Save tapi/6126598 to your computer and use it in GitHub Desktop.
An Xcode build phase script to automatically run mogenerator on your xcdatamodel if it has changed
# Xcode sets up its own PATH variable so we want to ensure that it includes /usr/local/bin
PATH=$PATH:/usr/local/bin
# Check that mogenerator is available
command -v mogenerator >/dev/null 2>&1 || { echo >&2 "You need mogenerator but it's not installed. To install using homebrew use 'brew install mogenerator'. Aborting."; exit 1; }
# Change the working dir to where our models are
cd "${SRCROOT}"/Models
# Only run mogenerator if the access time for ResultsCache.xcdatamodeld is newer than our lock file
MODEL_ACCESS=$[ $(stat -f '%m' ResultsCache.xcdatamodeld) ]
LOCK_ACCESS=$[ $(stat -f '%m' mogenerator.lock) ]
if [ $MODEL_ACCESS -gt $LOCK_ACCESS ]; then
# Run mogenerator
mogenerator -m ResultsCache.xcdatamodeld --includeh PXModels.h -M generated/ \
--template-path Templates \
--template-var arc=true \
--template-var frc=true \
--template-var project="${PROJECT}" \
--template-var user="${USER}" \
--template-var year=`date "+%Y"` \
--template-var date=`date "+%d-%m-%Y"` \
--template-var year=`date "+%Y"`
# Update the access times of our lockfile using our xcdatamodeld as a reference
touch -r ResultsCache.xcdatamodeld mogenerator.lock
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment