jksk / mogenerator

Core Data code generation

Home Page:http://rentzsch.github.com/mogenerator

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

#mogenerator + Xmo'd

Visit the project's pretty homepage.

Here's mogenerator's elevator pitch:

mogenerator is a command-line tool that, given an .xcdatamodel file, will generate two classes per entity. The first class, _MyEntity, is intended solely for machine consumption and will be continuously overwritten to stay in sync with your data model. The second class, MyEntity, subclasses _MyEntity, won't ever be overwritten and is a great place to put your custom logic.

Want more detail? John Blanco has authored a detailed writeup about mogenerator.

Using mogenerator

Senseful wrote up a nice summary of mogenerator's command-line options.

Using Xmo'd

Xmo'd (pronounced ex-mowed) is an Xcode 3 (Xcode 4 support is planned) plugin that integrates mogenerator into Xcode. It saves you the hassle of having to write a Run Script Build Phase and/or manually adding+removing source files from your project as you add+remove entities.

Xmo'd works by noticing when your *.xcdatamodel is saved. If the model file's Xcode project item comment contains xmod, an AppleScript is fired that creates a folder based on your model's file name and populates it with derived source code files from your model. It then adds the new folder to your project as a Group Reference and adds all the source files to your project.

Version History

v1.27: Mon Nov 12 2012 download

  • [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)

v1.26: Thu Apr 12 2012 download

  • [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) Xcode.app now lives in /Applications, so the installer needs to get smarter to cope.

v1.25: Thu Feb 16 2012 download

  • [NEW] Support for Xcode 4.3 and it's relocation of momc into its bundle. Only supports /Applications/Xcode.app 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.

v1.24: Wed Dec 6 2011 download

  • [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)

v1.23: Sun Jul 10 2011 download

  • [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] Support for momc error-reporting options: MOMC_NO_WARNINGS, MOMC_NO_INVERSE_RELATIONSHIP_WARNINGS and MOMC_SUPPRESS_INVERSE_TRANSIENT_ERROR. (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)

v1.22: Wed Mar 2 2011 download

  • [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)

v1.21: Mon Nov 1 2010 download

  • [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 Console.app) 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)

v1.20: Thu Aug 12 2010 download

  • [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)

v1.19: Sun 4 Jul 2010 download

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

v1.18: Thu 1 Jul 2010 download

  • [NEW] Xmo'd works with versioned data models. (rentzsch)

  • [NEW] Support for fetched properties (Nikita Zhuk)

  • [NEW] NSParameterAssert(moc) in fetch request wrappers. (rentzsch)

v1.17: Sat 27 Mar 2010 download

  • [NEW] +[Machine entityName] (for @drance) and +[Machine entityInManagedObjectContext:] (Michael Dales).

  • [NEW] --list-source-files option, which lists model-related source files. (rentzsch)

  • [NEW] Add --orphaned option. (rentzsch)

Couple --orphaned with --model to get a listing of source files that no longer have corresponding entities in the model. The intent is to be able to pipe its output to xargs + git to remove deleted and renamed entities in one command, something like:

$ mogenerator --model ../MyModel.xcdatamodel --orphaned | xargs git rm

v1.16: Mon 4 Jan 2010 download

  • [NEW] machine.h template now produces type-safe scalar attribute property declarations. (rentzsch)

  • [CHANGE] Remove machine.m implementations of to-many relationship setters. (rentzsch)

  • [CHANGE] Xmo'd: change file ordering to human.m, human.h, machine.m, machine.h (from human.h, human.m, machine.h, machine.m). (rentzsch)

  • [FIX] Missing space for fetch requests with multiple bindings. (Frederik Seiffert)

v1.15: Mon 2 Nov 2009 download

  • [CHANGE] Xmo'd: now adds .h human+machine header files to project (in addition to current .m + .mm files). (rentzsch)

  • [NEW] Now supports key paths in fetch request predicates so long as they're relationships. (Jon Olson)

  • [FIX] Log fetch-request-wrapper errors to NSLog() on iPhone since it lacks -[NSApp presentError:]. (rentzsch)

  • [NEW] +insertInManagedObjectContext: NSParameterAssert()'s its moc arg. (rentzsch)

v1.14: Fri 9 Oct 2009 download

  • IMPORTANT: 1.14 generates code that may be incompatible with clients of 1.13-or-earlier generated code. +newInManagedObjectContext: has been replaced with +insertInManagedObjectContext: and method implementations have been replaced with @dynamic, which don't work so well with overriding (most of these uses can be replaced with Cocoa Bindings). Upgrade only if you have spare cycles to fix-up existing projects.

  • [CHANGE] changed +newInManagedObjectContext: to +insertInManagedObjectContext: to satisfy the LLVM/clang static analyser. (Ruotger Skupin)

  • [CHANGE] Default machine templates now use @dynamic. The old templates still available in contributed templates/rentzsch non-dynamic. (Pierre Bernard)

  • [CHANGE] Xmo'd included again in default mogenerator installation -- the first time since 1.6. (rentzsch)

  • [CHANGE] Migrated project to github from self-hosted svn+trac installation.

  • [NEW] Xmo'd version checking whitelists Xcode versions 3.1(.x) and 3.2(.x).

  • [NEW] Dropped ppc support for Xmo'd. May reconsider if folks yelp. (rentzsch)

About

Core Data code generation

http://rentzsch.github.com/mogenerator

License:MIT License