iOS嵌套上下文在设备上较慢

时间:2013-08-28 09:25:13

标签: iphone ios objective-c core-data

我试图通过嵌套的上下文从一个NSManagedContext移动到多个。

我正在使用这些文章来帮助我:

实际系统

[myHTTPClient getPath:path
  parameters:@{access_token & stuff}
  success:^(AFHTTPRequestOperation *operation, id responseObject) {
    for (NSDictionary *dictionary in responseObject)
    {
      // filling the dic in a NSManagedObject
    }
    [myMainContext save:&error];
  }, failure:failureBlock];

通缉系统

[myHTTPClient getPath:path
  parameters:@{access_token & stuff}
  success:^(AFHTTPRequestOperation *operation, id responseObject) {
    __block NSManagedObjectContext *managedObjectContext = [(AppDelegate *)[[UIApplication sharedApplication] delegate] managedObjectContext];
    __block NSManagedObjectContext *writerObjectContext = [(AppDelegate *)[[UIApplication sharedApplication] delegate] writerManagedObjectContext];
    __block NSManagedObjectContext *temporaryContext = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSPrivateQueueConcurrencyType];
    temporaryContext.parentContext = managedObjectContext;
    NSEntityDescription *entity = [[self.fetchedResultsController fetchRequest] entity];

    [temporaryContext performBlock:^{
      for (NSDictionary *dictionary in responseObject)
      {
        // filling the dic in a NSManagedObject
      }
      [temporaryContext save:&error];
      [managedObjectContext performBlock:^{
        [managedObjectContext save:&error];
        [writerObjectContext performBlock:^{
          [writerObjectContext save:&error];
        }];
      }];
    }];
  }, failure:failureBlock];

Parent-Context Diagram

问题

我在使用此方法时保存数据时出现问题,但我解决了这个问题(参见https://stackoverflow.com/questions/18151827/coredata-writermanagedobjectcontext-freeze-when-save

但是,正如我在上一个问题中所说的,它在模拟器上加速2次,但它在设备上慢5倍。我使用iPod Touch 4th进行测试。

怎么可能,我该如何改进呢? 我并不反对使用这个图表:

Shared Persistent Store Diagram

但是我想找出如何将它集成到我的代码中,因为我尝试了它并没有改变任何东西。

谢谢。

0 个答案:

没有答案