mogenerator 1.28

What’s New:

  • [NEW] --v2 argument. I wanted to enable ARC by default, but decided to take it a step further (while not breaking existing scripts). The new --v2 argument is basically semantic versioning for tool arguments.

    So now instead of this:

    mogenerator --model MyDataModel.xcdatamodeld \
        --template-var arc=true \
        --template-var literals=true \
        --template-var modules=true

    You can write this:

    mogenerator --v2 --model MyDataModel.xcdatamodeld

    Internally these invocations are equivalent, but new scripts and manual invocations should use the --v2 variant.

    I recommend putting the --v2 in front of the rest of the arguments to call attention to the versioned context of the following arguments.

    This mechanism should allow mogenerator to continue to supply sensible defaults into the future as well. Perhaps --v3 will generate Swift by default. Speaking of which…

  • [NEW] Experimental Swift code generation. Unfortunately basic Core Data functionality (to-one relationships) is broken on 10.9, but we can still try writing theoretically-correct Swift code. Perhaps a future version of mogenerator will supply the needed work-around code for you. (Alexsander Akers, afrederick1, Piet Brauer, rentzsch, Chris Weber, Markus Chmelar, Brent Royal-Gordon)

  • [NEW] Ordered relationships actually work. OMG. I have them working in a new separate OS X test app, even though mogenerator’s test dir fails. I still haven’t figured out why, but I’m not holding this back. (Daniel Tull, Joshua Greene, Dave Wood, Jonathan del Strother)

  • [NEW] Custom scalar types. Specify attributeValueScalarType for the name of the property’s custom type and additionalHeaderFileName if you need to bring in an additional header file for compilation. With this, mogenerator supports C-style and JREnum-style enums. (Quentin ARNAULT)

  • [NEW] Remove unnecessary empty lines in the generated files. (Stephan Michels)

  • [NEW] Ability to forward-declare @protocols for i.e. transformable types. Specify them via a comma delimited string in the entity’s user info under the attributeTransformableProtocols key. (Renaud Tircher)

  • [NEW] Generate *UserInfo key/value pairs as const structs. (Jeremy Foo, rentzsch)

  • [NEW] --template-var literals which, when enabled, generates Obj-C literals. (Brandon Williams, Thomas van der Heijden, rentzsch)

  • [NEW] Specify --template-var modules=true option to avoid treating #import as an import of module 'CoreData' [-Wauto-import]" warning. (Daniel Tull)

  • [NEW] Unsigned integers are generated when a property’s minimum is set to 0 in the Xcode modeler. (Dan Pourhadi)

  • [NEW] Add support for setting command-line options via a JSON config file. (Simon Whitaker)

  • [NEW] Add file. It’s now even easier to contribute to mogenerator :) (rentzsch)

  • [NEW] Add MIT LICENSE file to make it clear templates are under the same license. (rentzsch)

  • [CHANGE] Suppress generation of -setPrimativeType: method. issue 16. (rentzsch)

  • [CHANGE] Add a warning when skipping an attribute named ‘type’. (Simon Whitaker)

  • [CHANGE] Add explicit atomic to sooth -Weverything. (Daniel Tull)

  • [CHANGE] iOS 8 changes objectID from a getter into a property, resulting in a warning. Templates updated to match. (Ryan Johnson)

  • [FIX] Support newly-created models when --model=*.xcdatamodeld. issue 137. (Sergey)

  • [FIX] Minor warning fix, 64->32 truncation, format strings. (Sean M)

  • [FIX] Machine headers always #imports their superentity if present. (David Aspinall)

  • [FIX] Fetch requests whose predicate LHS specifies a relationship. issue 15. (rentzsch)

  • [FIX] Don’t emit empty *UserInfo structs. (Jeremy Foo 1 2)

  • [FIX] Don’t emit empty *Attributes, *Relationships, and *FetchedProperties structs. (Daniel Tull)

  • [FIX] MOIDs subclass their superentity (instead of just always inheriting from NSManagedObject). (Daniel Tull)

  • [FIX] Don’t touch aggregate include files if the content didn’t change. (Stephan Michels)

  • [FIX] Don’t attempt to #import "NSManagedObject.h" even in the face of weird (corrupted?) model files. issue 42. (rentzsch)

  • [TEST] Escape spaces in mogenerator build path. (Daniel Tull)

mogenerator Sep 10 2014

Apple Claims Mogenerator’s Methods

When generating class files to represent your data model’s entities, mogenerator writes a few convenience class methods for you:

+ (id)insertInManagedObjectContext:(NSManagedObjectContext*)moc_;
+ (NSString*)entityName;
+ (NSEntityDescription*)entityInManagedObjectContext:(NSManagedObjectContext*)moc_;

These handy class methods allow you to write something like this:

[MyEntity insertInManagedObjectContext:moc];

to create a new instance. Contrast with:

[NSEntityDescription insertNewObjectForEntityForName:@"MyEntity" inManagedObjectContext:moc];

The mogenerator way is more obvious, less code and not stringly typed.

So that’s the backgrounder.

The good news is Apple likes mogenerator so much that they used it to implement iOS’s PhotoLibraryServices.framework.

The bad news is that PhotoLibraryServices.framework is a private framework.

As a first line of defense against naughty developers submitting apps that use undocumented APIs, Apple sweeps up every selector (method name) defined in all private frameworks and puts them on a special list. The “non-public selectors” list.

Unfortunately this includes the convenience methods mentioned above.

If your App Store submission is found to be use non-public selectors Apple may do nothing, issue a warning or reject your submission altogether.

※ ※ ※

I’m not sure what to do about this.

I could not supply the convenience methods and use Core Data directly like an animal. No! I won’t go back. I can’t go back.

Prefixing the methods (perhaps with an mo_) would provide relief, but only temporarily. When Apple upgrades PhotoLibraryServices to the newer version of mogenerator the cycle would begin anew.

NS is designed for optional class namespacing, but its concepts could be applied to method names as well. Unfortunately at the method level it uglies up the code and confuses Xcode’s code navigator popup menu. Also it would probably require NS_NAMESPACE preprocessor symbol be defined at the target or project level.

Apple could explicitly whitelist mogenerator’s convenience methods but I’m not holding my breath.

The next version of mogenerator could be released under an “Anyone But Apple” license. The idea is to allow everyone but Apple to use mogenerator. I could prefix the methods and issue the mogenerator upgrade knowing Apple couldn’t upgrade and claim the new methods as their own again.

Sadly, this seems like the most promising option.

(Thanks to Tony Arnold for the wording for the title of this post.)

Update Apr 18: First off, a clarification: it appears Apple has never rejected an application using mogenerator’s methods — they’ve only issued warnings.

Now for the good news: a little birdie has told me Apple has whitelisted mogenerator’s methods.

mogenerator appstore Apr 12 2014

mogenerator 1.27

What’s New:

  • [NEW] You can now pass .xcdatamodeld paths to mogenerator. mogenerator will look inside the directory, read its hidden .xccurrentversion file and use the “current” .xcdatamodel file. (Alexander Zats)

  • [NEW] Replaced mogenerator’s previous testing system (the test mule) with a new Rakefile-based system that eases building & testing from the current source tree and tests both MRC and ARC. (rentzsch)

  • [NEW] Property declarations generated from attributes can now be qualified as readonly by adding a mogenerator.readonly to an attribute’s userinfo. (crispinb)

  • [NEW] --configuration option that limits generation to the specified configuration. (Sixten Otto)

  • [NEW] --base-class-import option for fine-grained control of base class import statements. (David Aspinall)

  • [CHANGE] Optimized keyPathsForValuesAffectingValueForKey: generated code (returns after first match). (Sean M)

  • [CHANGE] Add default private class extension to human source template. (Jonas Schnelli)

  • [FIX] Align generated code’s pointer asterisks more consistently. (Tony Arnold)

  • [FIX] Missing import when using mogenerator.customBaseClass entity userinfo key. (Thomas Guthrie)

  • [FIX] Handle case in generated fetch request wrapper machine code when predicate variables are repeated. (Sergei Winitzki)

  • [FIX] Explicitly set mogenerator project’s deployment target to 10.6 to avoid segfaulting on 10.8 for some reason. issue 121 (reported by Sixten Otto, diagnosed by Florian Bürger)

  • [FIX] Cast to unsigned in machine source to avoid clang format string warning. (rentzsch)

  • [FIX] Don’t attempt to report errors through -[NSApp reportError:] in generated machine source unless targeting AppKit. (rentzsch)

  • [WORKAROUND] Recent versions of Xcode use an empty string to mark entities that do not have a custom subclass. (Matthias Bauch)

  • [CHANGE] make_installer.command: assume PackageMaker now lives in /Applications/Utilities. (rentzsch)

mogenerator Nov 14 2012

mogenerator 1.26

What’s New:

  • [FIX] Missing space in transformable attribute codegen. issue 89 (Daniel Tull, Kris Markel, Whitney Young)

  • [NEW] mogenerator’s standard templates are now bundled into the mogenerator binary itself. This should solve the problem of templates growing out of sync with the intended version of mogenerator (exacerbated by the now-popular homebrew installer). You can still use your own templates with the --template-path and --template-group parameters. issue 79 (Ingvar Nedrebo, rentzsch).

  • [NEW] Support for per-entity custom base classes, set via mogenerator.customBaseClass key in the entity’s user info. (Trevor Squires)

  • [CHANGE] mogenerator installer no longer installs separate template files (but it won’t touch those already installed).

  • [CHANGE] mogenerator’s .pkg installer no longer includes Xmo’d since 1) Xmo’d doesn’t work with Xcode 4 yet and 2) now lives in /Applications, so the installer needs to get smarter to cope.

mogenerator Apr 12 2012

mogenerator 1.25

What’s New:

  • [NEW] Support for Xcode 4.3 and it’s relocation of momc into its bundle. Only supports /Applications/ for now. (Matt McGlincy)

  • [CHANGE] Now generates size-specific scalar types (int16_t, int32_t, int64_t) instead of size-variable types (short, int, long long). bug 2 (Rob Rix)

  • [NEW] Can now generate NSFetchedResultsController creation code for to-many relationships (use --template-var frc=true). (Daniel Tull)

  • [DOC] Link to John Blanco’s Getting Started with Mogenerator.

mogenerator Feb 17 2012

mogenerator 1.24

What’s New:

  • [FIX] Was incorrectly using -mutableSetValueForKey: for ordered relationships instead of -mutableOrderedSetValueForKey:. bug 75 (Martin Schürrer)

  • [NEW] Now generates Mike Ash-style constant structures for attributes, relationships and fetched properties. This allows you to write code like [obj valueForKey:PersonMOAttributes.age]. Tip: you’ll need to enable ARC generation (--template-var arc=true) if you’re using ARC. (Daniel Tull)

  • [NEW] --base-class-force option, for specifying a base class even if the model file’s entities don’t specify one. (Joe Carroll)

  • [NEW] PONSO: NSSet-based templates, improved inverse relationship logic and plug memory leak. (Tyrone Trevorrow)

  • [FIX] PONSO: Added import for super entity in machine headers. (Tyrone Trevorrow)

  • [FIX] Migrate from deprecated -[NSString initWithContentsOfFile:] and fix a MiscMerge warning where an immutable object was assigned to a mutable ivar. (Joshua Smith)

mogenerator Dec 8 2011

mogenerator 1.23

What’s New:

  • [NEW] Support for Mac OS X 10.7 Lion’s ordered relationships (generated relationship code uses NSOrderedSet and NSMutableOrderedSet). (rentzsch 1 2 3)

  • [NEW] Optional support for ARC: pass --template-var arc=true to mogenerator. bug 63 (Adam Cox)

  • [NEW] New template that dumps a binary .xcdatamodel into a pseudo-ASCII-plist format perfect for diffing. A great way to compare two versions of a data model. (Brian Webster)

  • [NEW] Attributes and relationships are now sorted for generation. This should eliminate spurious changes to source files when unrelated model entities are changed. After upgrading to 1.23 you probably want to regenerate all your source files without a model change, just to let things settle in before your next real model change. (Nikita Zhuk)

  • [NEW] Support for generation of PONSOs: Plain Old NSObjects. These are in-memory, typesafe non-CoreData classes generated from your Xcode data models. Generate reams of ObjC classes from a single data model. Supports relationships and basic serialization. See contributed templates/Nikita Zhuk/ponso/README.txt for details. (Nikita Zhuk)


  • [NEW] Now generates output directories if they don’t already exist or presents an error message if they cannot be created. (Scott Little)

  • [CHANGE] Change #include to #import in include.m. (Zac Bowling)

  • [NEW] You can now use --template-var to pass arbitrary command-line options through to templates. (Adam Cox)

  • [NEW] Update MiscMerge to NS(U)Integer for 64-bit compatibility. (Nikita Zhuk)

  • [FIX] Memory leaks in MiscMerge. (Nikita Zhuk)

  • [CHANGE] mogeneratorTestMule’s mogenerate.command upgraded to use double-dash option names. (rentzsch)

  • [FIX] Set mogeneratorTestMule’s mogenerate.command executable bit. (rentzsch)

mogenerator Jul 23 2011

mogenerator 1.22

What’s New:

  • [FIX] Xmo’d 1.21 introduced a bug where it would no longer create a source folder for your data model (it would work fine it one already existed). bug 43 (rentzsch)

  • [NEW] -keyPathsForValuesAffectingValueForKey: is now generated in machine.m files, populated by your entity’s scalar attributes. The idea is code like myObject.myIntAttributeValue++ tells Core Data that myIntAttribute has changed (handy when you’re KVO-observing myIntAttribute). (Tony Arnold)

  • [NEW] When a model file has multiple versions (.xcdatamodeld files) Xmo’d now uses the “current” version of the model (set the “xmod” command on the xcdatamodeld group). (Vincent Guerci)

  • [NEW] Support undefined attribute types. (Brian Doig)

  • [NEW] mogenerator and Xmo’d now supports model-relative paths for the --template-path argument. (tonklon)

mogenerator Mar 3 2011

mogenerator 1.21

What’s New:

  • [NEW] Machine templates now include fetched properties by default. (Jonathan del Strother)

  • [NEW] Xmo’d: better support for --(machine|human|output)-dir model option path: now they can be full or relative to the model file. Xcode group and file references are no longer deleted/re-added with every save. (John Turnipseed)

  • [NEW] Xmo’d: --log-command model option. When enabled, Xmo’d will log (to the generated+executed mogenerator invocation. Good for automation debugging and also can provide training wheels for using mogenerator directly. (rentzsch)

  • [FIX] Avoid nil substitution dictionary in generated fetch request wrapper code, which resulted in an NSInvalidArgumentException reason “Cannot substitute a nil substitution dictionary.” (Anthony Mittaz)

mogenerator Nov 1 2010

mogenerator 1.20

What’s New:

  • [NEW] Xmo’d: model comments that start with -- are passed as args to mogenerator. This allows accessing command-line options such as --base-class. (David LeBer)

  • [NEW] Forward-declare transformable attribute class types. bug 11 (seanm)

  • [CHANGE] Generated accessors that return BOOLs now return NO instead of 0, avoiding LLVM Static Analyzer warnings. bug 8 (seanm)

  • [CHANGE] Generated value accessors that return ints no longer needlessly check for nil. bug 10 (seanm)

  • [CHANGE] LLVM 2/Xcode 4 doesn’t like [NSDictionary dictionaryWithObjectsAndKeys:nil], issuing a “missing sentinel in method dispatch” warning. Add hasBindings to prettyFetchRequests so we can just generate NSDictionary *substitutionVariables = nil in that case. (Anthony Mittaz)

  • [FIX] Variable shadowing bug which would cause v1.19’s xcode-select functionality to always fail. (Nikita Zhuk)

Forgot to mention v1.19 here:

  • [NEW] Use xcode-select to dynamically discover our way to momc instead of only hard-coding /Developer. (Josh Abernathy)

mogenerator Aug 12 2010