Skip to content

Automatic generation for versioned data models #7

Closed
nvie opened this Issue Dec 4, 2009 · 5 comments

4 participants

@nvie
nvie commented Dec 4, 2009

When you have added a version to your Core Data model (Design > Data Model > Add Model Version), automatic entity generation using the 'xmod' comment text stops working.

It's not exactly clear to me whether this should work, is still unimplemented, or whether the 'xmod' comment tag should be placed elsewhere (for example on the .xcdatamodeld directory?).

Any experiences with versioned models and auto-generating classes?

@amrox
amrox commented Dec 4, 2009

I'm just using mogenerator directly, and not the automatic generation with xmod.

I wrote a script around mogenerator to grab the current model version. Here are the pertinent lines:

DATAMODEL_WRAPPER="path/to/your/model.xcdatamodeld"
DATAMODEL_CURRENT=`/usr/libexec/PlistBuddy -c "print _XCCurrentVersionName" "$DATAMODEL_WRAPPER"/.xccurrentversion`
DATAMODEL_PATH="$DATAMODEL_WRAPPER/$DATAMODEL_CURRENT"
@rentzsch
Owner

Yeah, I haven't implemented direct support for versioned models yet. Patches welcome :-)

@adib
adib commented Jan 16, 2010

Here's a preliminary script that can be used as a build phase from amrox's script:

#!/bin/bash
# mogeneratorv MoGenenerator for versioned model
# http://github.com/rentzsch/mogenerator/issues/unreads#issue/7
#
# Revision History
# 16-Jan-10     Sasmito Adibowo     initial creation
#

DATAMODEL_WRAPPER="$1"
if [ ! -f "$DATAMODEL_WRAPPER/.xccurrentversion" ];
then
    echo  file "$DATAMODEL_WRAPPER/.xccurrentversion" does not exists - exiting.
    exit 3
fi
DATAMODEL_CURRENT=`/usr/libexec/PlistBuddy -c "print _XCCurrentVersionName" "$DATAMODEL_WRAPPER"/.xccurrentversion`
DATAMODEL_PATH="$DATAMODEL_WRAPPER/$DATAMODEL_CURRENT"
DATAMODEL_FILE=`basename "$DATAMODEL_PATH"`
DATAMODEL_DIR=`dirname "$DATAMODEL_WRAPPER"`
DATAMODEL_NAME=`expr "$DATAMODEL_FILE" : "\(.*\)\.xcdatamodel"`

echo Data model: "$DATAMODEL_PATH"
echo Model directory: "$DATAMODEL_DIR" 
echo Output Directory: "$DATAMODEL_DIR/$DATAMODEL_NAME"

if [ ! -d "$DATAMODEL_DIR/$DATAMODEL_NAME" ]
then
    mkdir "$DATAMODEL_DIR/$DATAMODEL_NAME"
fi


mogenerator -m "$DATAMODEL_PATH" -O "$DATAMODEL_DIR/$DATAMODEL_NAME"
@adib
adib commented Nov 20, 2010

Looks like version 1.21 broke the ability to generate versioned data model. Here is an update to the workaround script. The script now correctly identify the versioned data model name as the output directory

#!/bin/bash
# mogeneratorv MoGenenerator for versioned model
# https://github.com/rentzsch/mogenerator/issues/7
# Revision History
# 16-Jan-10 Sasmito Adibowo initial creation
# 20-Nov-10 Sasmito Adibowo Now uses the versioned data model name as the base name for the output directory

DATAMODEL_WRAPPER="$1"
if [ ! -f "$DATAMODEL_WRAPPER/.xccurrentversion" ];
then
    echo  file "$DATAMODEL_WRAPPER/.xccurrentversion" does not exists - exiting.
    exit 3
fi
DATAMODEL_CURRENT=`/usr/libexec/PlistBuddy -c "print _XCCurrentVersionName" "$DATAMODEL_WRAPPER"/.xccurrentversion`
DATAMODEL_PATH="$DATAMODEL_WRAPPER/$DATAMODEL_CURRENT"
DATAMODEL_FILE=`basename "$DATAMODEL_PATH"`
DATAMODEL_DIR=`dirname "$DATAMODEL_WRAPPER"`

WRAPPER_NAME=`basename ${DATAMODEL_WRAPPER}`
DATAMODEL_NAME="${WRAPPER_NAME%.*}"

echo Data model: "$DATAMODEL_PATH"
echo Model directory: "$DATAMODEL_DIR" 
echo Output Directory: "$DATAMODEL_DIR/$DATAMODEL_NAME"

if [ ! -d "$DATAMODEL_DIR/$DATAMODEL_NAME" ]
then
    mkdir "$DATAMODEL_DIR/$DATAMODEL_NAME"
fi

mogenerator -m "$DATAMODEL_PATH" -O "$DATAMODEL_DIR/$DATAMODEL_NAME"
@rentzsch
Owner

Direct support added: #46

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.