问题是 Reskit 是否使用 CoreData,因为我不知道使用它有什么好处,或者在什么情况下建议使用它。
这个问题是因为我有一个带有 CoreData 的应用程序(老开发人员做的),我觉得它消耗了大量资源并使应用程序变慢。
我有一个新闻源,所以这里的数据总是在变化,所以我不需要保留我认为的数据?但是我有一些对象,例如我的个人资料图片和偏好,我想在本地存储。
*更新*
这是定义“持久性”的代码(我认为)
NSManagedObjectModel *managedObjectModel = [NSManagedObjectModel mergedModelFromBundles:nil];
RKObjectManager* man = [RKObjectManager managerWithBaseURL:[NSURL URLWithString:BASE_URL]];
man.requestSerializationMIMEType = RKMIMETypeJSON;
[RKObjectManager setSharedManager:man];
[AFNetworkActivityIndicatorManager sharedManager].enabled = YES;
RKManagedObjectStore *managedObjectStore = [[RKManagedObjectStore alloc] initWithManagedObjectModel:managedObjectModel];
man.managedObjectStore = managedObjectStore;
//configuring Mappings
/**some mappings**/
[managedObjectStore createPersistentStoreCoordinator];
NSString *storePath = [RKApplicationDataDirectory() stringByAppendingPathComponent:@"Database.sqlite"];
NSError *error;
NSPersistentStore *persistentStore = [managedObjectStore addSQLitePersistentStoreAtPath:storePath fromSeedDatabaseAtPath:nil withConfiguration:nil options:nil error:&error];
NSAssert(persistentStore, @"Failed to add persistent store with error: %@", error);
// Create the managed object contexts
[managedObjectStore createManagedObjectContexts];
// Configure a managed object cache to ensure we do not create duplicate objects
managedObjectStore.managedObjectCache = managedObjectStore.managedObjectCache;
最佳答案
使用核心数据。另请参阅使用获取的结果 Controller (以管理数据存储中数据页面的批量加载)。这对于新闻源应用程序来说是完美的,您可能拥有相对大量的源项目,但在任何时候都不会显示很多项目(因此您不需要将它们存储在内存中)。使用原始 SQLite 或磁盘文件中的数据自行管理此操作将需要更多工作,而且性能可能会较差。
关于ios - CoreData 与否与 Restkit,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19777436/