CoreData - Mogenerator 的使用

来源:互联网 发布:笨太子 知乎 编辑:程序博客网 时间:2024/05/16 10:52

Why use Mogenerator instead of XCode directly:

Mogenerator is a program that builds two custom classes for each entity in a Core Data model: a machine version and a human version.

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

 

The machine version handles the basic behavior you need from a custom Core Data class (like Xcode’s generated classes). It is expected that the machine version will get overwritten every time the model changes, so you should not make any changes here(they will be lost).

The human version extends the machine version and is the class you modify for your own app specific behavior.

 

Steps to generator the Machine Files and Human Files for xcodemodel database.

1. Download Mogenerator from:

             https://github.com/rentzsch/mogenerator/

         I used latest version v1.26: Thu Apr 12 2012download

2. Install the mogenerator-1.26.dmg from your download folder.

3. Start the console and go the resource folder

4. Run the command below to generator the files:

     mogenerator -m RobertLiu.xcdatamodeld/RobertLiu.xcdatamodel -M Model -H Entities

    If your application need support ARC, you need to use below command:

    mogenerator --template-var arc=true -m RobertLiu.xcdatamodeld/RobertLiu.xcdatamodel -M Model -H Entities

5. You will see the results:

     xxx machine files and xxx human files generated.

 

Notes:

1. Beside the command line, mogenerator supports the xmod, which is integrated with Xcode.  here is the reference to setup xmod.

             http://raptureinvenice.com/getting-started-with-mogenerator/

 

2. In case you want to uninstall mogenerator and try the previous version, such asv1.25: Thu Feb 16 2012download, please just remove below files:

             •  /usr/bin/mogenerator

             •  /private/var/db/receipts/com.rentzsch.mogenerator.bom          

             •  /private/var/db/receipts/com.rentzsch.mogenerator.plist

原创粉丝点击