Mantle and Core Data : Only one Model

ぃ、小莉子 提交于 2019-12-23 13:25:11

问题


I'm starting to use Core Data with my Mantle Object (MTLModel) following this tutorial: http://chroman.me/core-data-and-mantle-one-to-many-relationship/

This article said :

Since model classes inherit from NSManagedObject, which means that they can’t inherit from MTLModel, we need to use separated classes for Mantle and Core Data

So, I have two class with the same properties:

  • TrackMTL.m (MTLModel)
  • Track.m (NSManagedObject)

I'm looking for une solution without be forced to create two Model for the same Object and without use wrapper like Overcoat.


回答1:


You don't have to use 2 classes, just add this to your MTModel :

<MTLJSONSerializing, MTLManagedObjectSerializing>

and for the properties your have to implements this :

+ (NSDictionary *)managedObjectKeysByPropertyKey


来源:https://stackoverflow.com/questions/28720920/mantle-and-core-data-only-one-model

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!