ios - CoreData 与否与 Restkit

标签 ios iphone core-data restkit

问题是 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/

相关文章:

iphone - objective c 类方法返回值,分配给弱/强属性

ios - "Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value"- swift

ios - UIView +animateWithDuration : isn't animating a recently allocated view correctly

ios - 将 UITextField 背景设置为 .clearColor 时,为什么我的 UITextField 占位符会消失?

ios - 保护 iPhone 应用程序的数据馈送

iphone - 如何在Window中创建c/c++库,并在iPhone项目中使用?

ios - 为什么我的位置是:sticky not working on iOS?

iphone - 核心数据对多关系。它们是延迟加载吗?

ios - CoreData困境: entity without inverse relationship

ios - 升级到 Xcode 7 会在 CoreData 模型上创建 "Missing current version declaration"警告