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
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.
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:
- If it's a
.mom, that is, a single managed object model,
- If it's a
.momd(which potentially contains multiple managed object models),
.xcdatamodeldcontaining all models found, as well as a
.xccurrentversionfile (if appropriate) indicating the current version.
- If it's a
momdeclocates the first
.momdin the bundle and decompiles it.
- If it's an iCloud-style
momdeclocates the enclosed data model and produces a
momdec Foo.mom /private/tmp/
Foo.xcdatamodel in /private/tmp/
Foo.xcdatamodeld in the current working directory. This bundle will include all model versions present in the
momd and (if appropriate) a
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;
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;
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.
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.
MIT-style license, see LICENSE for details.
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:
- Min/max values on Core Data decimal attributes will not be correct if the limits are not integers, because Xcode truncates the limits to integers at compile time (rdar://problem/13677527, also on OpenRadar).
- Fetch requests will be missing any non-default values for the following settings, because they are lost when compiling with Xcode (rdar://problem/13863607, also on OpenRadar):
- Result Type
- Fetch limit
- Batch size
- Include Subentities
- Include Property Values
- Return Objects as Faults
- Include Pending Changes
- Return Distinct Results
By Tom Harrington, @atomicbird on most social networks.