
.xcdatamodel ファイルを元に自動生成Create NSManagedObject Subclass... と同じhuman と machine の2種類のクラスを生成human は machine のサブクラスとして実装されているhuman は上書きされないのでユーザーがモデルに対して追加の実装を書けるmachine は実行する度に上書きされるのでユーザーは触らないクラス例) CoreData.xcdatamodel にPerson というEntityがあるの場合
_Person.{h,m}(machine)Person.{h,m} (human) インストーラーでインストール
Homebrewでインストール
brew install mogenerator
$ mogenerator \
--template-var arc=true \ # ARC有効のテンプレを使う
-m /path/to/Model.xcdatamodeld \
-O /path/to/output/
-m で .xcdatamodeld を指定-O で 生成したモデルクラスの出力先を指定--template-var arc=true は テンプレートに arc=true という値を渡すという意味initializer が増えるextern const struct EventAttributes {
__unsafe_unretained NSString *sortIndex;
__unsafe_unretained NSString *timeStamp;
} EventAttributes;
NSDate *beginDate = ...;
NSDate *endDate = ...;
[NSPredicate predicateWithFormat:@"(%@ <= %K) AND (%K <= %@)",
beginDate,
EventAttributes.timeStamp,
EventAttributes.timeStamp,
endDate];
NSManagedObject がモデルの親クラス--base-class 親クラス名 を指定すると、親クラスを指定出来るhuman -> machine -> base-class
arc=true で吐くものが変わるように分岐がある<$if TemplateVar.arc$>
@property (nonatomic, strong) <$Relationship.immutableCollectionClassName$> *<$Relationship.name$>;
<$else$>
@property (nonatomic, retain) <$Relationship.immutableCollectionClassName$> *<$Relationship.name$>;
<$endif$>
テンプレートをいじれば
mogenerator-templates 内にmachine.{h,m}.motemplate と human.{h,m}.motemplate を作成する--template-path /path/to/mogenerator-templates/ でテンプレートディレクトリのパスを指定する.momd 、 .mom から .xcdatamodel などはデコンパイル出来る.xcdatamodelからはmogeneratorでモデルクラスを生成できる