CoreData or Not with Restkit



问题是是否将CoreData与Reskit一起使用,这是因为我不知道使用它有什么好处,或者在什么情况下建议使用它。

这个问题是因为我有一个带有 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;

使用核心数据。另请查看使用提取的结果控制器(以管理从数据存储中批量加载数据页面)。这对于新闻源应用程序来说是完美的,在新闻源应用程序中,您可能拥有相对大量的源项,但任何时候都不会显示其中的很多源项(因此您不需要它们在内存中)。使用原始SQLite或磁盘上文件中的数据自行管理将需要更多的工作,并且可能性能较低。

最新更新