• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
SOLVED: Programatically manipulating an xcdatamodel package?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

SOLVED: Programatically manipulating an xcdatamodel package?


  • Subject: SOLVED: Programatically manipulating an xcdatamodel package?
  • From: Allen Cronce <email@hidden>
  • Date: Sat, 7 Jun 2008 06:44:14 -0700

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 (email@hidden)

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:
This email sent to email@hidden


  • Follow-Ups:
    • Re: SOLVED: Programatically manipulating an xcdatamodel package?
      • From: "I. Savant" <email@hidden>
  • Prev by Date: Re: knowing when WebView is done
  • Next by Date: Re: SOLVED: Programatically manipulating an xcdatamodel package?
  • Previous by thread: Re: Learning Cocoa with RubyCocoa
  • Next by thread: Re: SOLVED: Programatically manipulating an xcdatamodel package?
  • Index(es):
    • Date
    • Thread