Home

Awesome

momdec: Core Data Model Decompiler

momdec is a command-line tool for Mac OS X that takes a compiled Core Data model and decompiles it to produce an equivalent xcdatamodel or xcdatamodeld suitable for use in Xcode. The resulting model file can also be used with mogenerator to produce source code files for Core Data entities which have custom subclasses.

Usage

momdec (Foo.mom|Foo.momd|Foo.app|baseline.zip) [output directory]

The first argument is the full path used to locate a compiled managed object model file, and the second is the location where the results should be written. If the second argument is omitted, the current working directory is used. Output files are automatically named based on the inputs.

The first argument can be one of several possibilities:

Command line

momdec Foo.mom /private/tmp/

Creates Foo.xcdatamodel in /private/tmp/

momdec Foo.momd

Creates Foo.xcdatamodeld in the current working directory. This bundle will include all model versions present in the momd and (if appropriate) a .xccurrentversion file.

Source code

This project includes a number of categories on Core Data classes which could be used in other projects. The main entry point would be in NSManagedObjectModel+xmlElement.h, which includes the following methods:

- (NSXMLElement *)xmlElement;

Returns an NSXMLElement representing the model

- (NSXMLDocument *)xmlDocument;

Returns a full NSXMLDocument representing the model. This just calls xmlElement, sets that element as the document root, and adds document-level metadata.

+ (NSString *)decompileModelAtPath:(NSString *)modelPath inDirectory:(NSString *)resultDirectoryPath error:(NSError **)error;

Decompiles the mom, momd, app, or baseline.zip at the specified path, saves the contents in the result directory, and returns the full path of the decompiled model.

Other categories consist of just an xmlElement method, which returns an NSXMLElement representing the receiver's portion of the decompiled model document.

Requirements

Developed with Mac OS X 10.8.3 and Xcode 4.6.1. May work with older versions of both, but this has not been tested.

License

MIT-style license, see LICENSE for details.

Limitations

Models that were compiled with Xcode may be missing some data due to the following bugs. Since this data does not exist in the compiled model file, momdec cannot restore it when decompiling the model:

Credits

By Tom Harrington, @atomicbird on most social networks.