Skip to content

Instantly share code, notes, and snippets.

@casademora
Created July 6, 2011 13:47
Show Gist options
  • Save casademora/1067256 to your computer and use it in GitHub Desktop.
Save casademora/1067256 to your computer and use it in GitHub Desktop.
Regenerate Core Data files in an Xcode project
## Add this as a 'Run Script' step in your Xcode Project prior to the compile step
mogen=`which mogenerator`
if [[ -x $mogen ]]; then
echo "Updating data objects using $mogen"
cd "$PROJECT_DIR/Model" && $mogen -m MyProject.xcdatamodeld/MyProject.xcdatamodel -M ./generated -H ./entities
fi
@diederich
Copy link

Add this as a 'Run Script' step in your Xcode Project prior to the compile step

mogen=`which mogenerator`
PlistBuddy=/usr/libexec/PlistBuddy
HUMAN_FILES_OUTPUT_FOLDER=./entities
MACHINE_FILES_OUTPUT_FOLDER=./generated
MODEL_DATA_FOLDER=MyProject.xcdatamodeld

#figure out current model version
CURRENT_MODEL_VERSION=`"$PlistBuddy" -c 'Print _XCCurrentVersionName' "$MODEL_DATA_FOLDER/.xccurrentversion"`


if [[ -x $mogen ]]; then
  echo "Updating data objects from $MODEL_DATA_FOLDER/$CURRENT_MODEL_VERSION using $mogen"
  "$mogen" -m "$MODEL_DATA_FOLDER/$CURRENT_MODEL_VERSION" -M "$MACHINE_FILES_OUTPUT_FOLDER" -H "$HUMAN_FILES_OUTPUT_FOLDER"
fi

@casademora
Copy link
Author

mogen=`which mogenerator`
PlistBuddy=/usr/libexec/PlistBuddy
HUMAN_FILES_OUTPUT_FOLDER=$PROJECT_DIR/Application/Models/entities
MACHINE_FILES_OUTPUT_FOLDER=$PROJECT_DIR/Application/Models/generated
MODEL_DATA_FOLDER=$PROJECT_DIR/Application/Models/MyProject.xcdatamodeld

#figure out current model version
CURRENT_MODEL_VERSION=`"$PlistBuddy" -c 'Print _XCCurrentVersionName' "$MODEL_DATA_FOLDER/.xccurrentversion"`


if [[ -x $mogen ]]; then
  echo "Updating data objects from $MODEL_DATA_FOLDER/$CURRENT_MODEL_VERSION using $mogen"
  "$mogen" -m "$MODEL_DATA_FOLDER/$CURRENT_MODEL_VERSION" -M "$MACHINE_FILES_OUTPUT_FOLDER" -H "$HUMAN_FILES_OUTPUT_FOLDER" --template-var arc=true
fi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment