« PSIG 106 | NSToolbar | Main | Beautiful Code and Beautiful Software »

PSIG 107 | Xmo'd + mogenerator: Seamless Core Data code generation

Saturday, October 13, 2007

(What is PSIG? | PSIG 107 announcement)

Show and Tell


Xmo'd + mogenerator: Seamless Core Data code generation

Mogenerator refresher (from PSIG 98):

Object relational mappers integrate object-oriented software with relational databases. They allow you to work with objects instead of raw SQL statements. Classes map to tables, and rows map to instances. There are a few different ways to implement this:

Core Data can generate wrappers for all of your attributes as NSManagedObject classes or as custom subclasses of NSManagedObject. Custom subclasses are great for holding your business logic and helping with type safety. The problem is that it's kind of a tedious task to get Xcode to generate your subclasses and it usually involves a lot of painful merging due to the fact that each file contains both generated and custom code.

You can use the lovely Generation Gap pattern to help with the merging problem: put machine-generated and custom code in separate files and make your custom code subclass the generated code.

This is where mogenerator comes in -- it's a command-line tool that automates everything and makes use of this pattern. mogenerator owns the machine's files which are subclassed off of NSManagedObject, and subclassed files off of that are owned by you and untouched by the machine. When you modify your data model and invoke mogenerator, all your generated code will be updated but your custom code won't change.

Xmo'd

Xmo'd makes your life even easier by integrating mogenerator into Xcode. Wolf achieved this with the use of undocumented, reverse-engineered plugin API. Xmo'd overrides the data model document method to automatically run mogenerator for you. When you save a data model document in Xcode, the Xmo'd override fires off an AppleScript which calls mogenerator. This keeps your generated code continuously synced up with your data model. Xmo'd also adds the menu item "Autocustomize Entity Classes." Currently it works on Xcode 2; Xcode 3 support is coming soon.

11:55 PM

Comments

Is the piggyback robot the wave of the future? I've heard a year or so back that a nurse robot has been invented - it can lift heavy patients with all the tenderness of a slightly animated cadaver.

Posted by Qwerty the cucumber at October 21, 2007 6:04 PM

The way he smiled at that moment was--it was as if all the candle flames in the room at that moment grew suddenly thinner, like slits in the dark. He put his hand--it was a healthy hand--on my shoulder.

"You know how they say that a human can be fully functional with only half a brain?"

He paused--and I remembered the proverb: "240 Is The Color Of My Name"--to breathe, and then finished.

"They were only half right."

------------

"When I get bad grades, my worldly appetite drops considerably."

"Do not wink at me. Do not pucker your lips at me. You may smile at me. But do not laugh at me."

Posted by Weien at October 25, 2007 11:20 AM