As suspected, I couldn't come up with a way to directly edit the xcdatamodel. I tried using NSKeyedUnarchiver to obtain the object graph for the xcdatamodel's "elements" plist. This failed because the resulting objects are implemented in the private XDBase framework.

To solve the problem I wrote a command line tool that does the following:

1. Compiles the model into a temp file using Xcode's momc.
2. Initializes an NSManagedObjectModel object with the compiled model.
3. Enumerates and manipulates the NSManagedObjectModel object in memory.
4. Uses NSKeyedArchiver archiveRootObject to write out the modified mom file.

Once I've got the modified mom file, I manually import it back into a clean data model using Xcode. At this point, the updated model can be viewed or edited using Xcode's data modeling tool.

Best,

Allen Cronce

On Jun 1, 2008, at 10:07 AM, Allen Cronce wrote:

Hi all,

I'm interested in programmatically manipulating "User Info" key/ value pairs in a large data model package. The resulting saved xcdatamodel package will be used for automatic code generation via mogenerator and custom templates. This doesn't have to happen often, so it does not need to be fancy or automated.

I'm open to any way to do this, including scripting Xcode to modify the model, or writing a command line utility that manipulates the package directly. Unfortunately a cursory look at the "elements" plist file indicates to me that manipulating its proprietary structure might be challenging.

Maybe the right way to do this is to momc the xcdatamodel package, manipulate the compiled result with the NSManagedObjectModel API's, then import the .mom file back into Xcode?

Thanks in advance for any suggestions.

Best,

Allen Cronce

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to