【发布时间】:2015-07-31 06:27:30
【问题描述】:
我有两个实体“Person”和“Car”来自网络服务。 我需要通过核心数据将其存储在 sqlite 中。我想知道我应该将 save 方法与 NSmanagedobject 绑定还是在实用程序或管理器中以不同方式编写的最佳方法是什么?
**Approach 1**
@interface Person : NSManagedObject
@property (nonatomic, retain) NSString * title;
- (void) saveManagedObject:(NSDictionary*)response //Responsible for init the person object and save in context
@end
**Approach 2**
@interface CoreDataUtility : NSObject
- (void) saveManagedObject:(NSDictionary*)response //Responsible for create the person object and save in context
@end
【问题讨论】:
-
对此的旁注,您添加到
NSManagedObject类的任何方法都应该在一个类别中执行。如果您更改CoreData布局并重新生成文件,您的方法将丢失。 -
感谢您的留言 :)。
-
你能给我推荐一个好的方法吗?
-
@SauravNagpal 嗨。 CoreData 的最佳实践 - Mogenerator + MagicalRecord
-
@SauravNagpal 看看这个教程youtube.com/watch?v=N2sZ9IjDBzs
标签: ios iphone core-data xcode6