本文介绍了Core Data中的cryptic错误:NSInvalidArgumentException,reason:referenceData64仅为抽象类定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一个iPhone应用程序,从XML文件读取数据,将其转换为Core Data Managed Objects并保存。

I'm doing an iPhone app that reads data from XML file, turn them into Core Data Managed Objects and save them.

应用程序工作正常, ,包含约150个对象的较小数据集/ XML。我说的主要是因为10%的时间,我会得到以下异常CoreData,同时尝试保存上下文:

The application is working fine, mostly, on smaller data set/XML that contains ~150 objects. I said mostly because 10% of the time, I'd get the following exception from CoreData while trying to save the context:

*由于未捕获终止应用程序exception'NSInvalidArgumentException',reason:'* -_referenceData64只为抽象类定义。定义 - [NSTemporaryObjectID_default _referenceData64]!'

* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* -_referenceData64 only defined for abstract class. Define -[NSTemporaryObjectID_default _referenceData64]!'

对于更大的数据集(〜2000),这种情况每次发生,但不在同一个地方。它可能失败在第137记录,第580,或最后一个。我尝试移动保存点(每个对象,每10个对象,保存一旦所有的对象被分配/ init'ed),但我总是碰到上面的异常。

On a bigger data set (~2000), this happens every time, but not on the same place. It could fail on the 137th record, 580th, or the very last one. I've tried moving the save point (per object, per 10 objects, save once all objects are alloc/init'ed) but I always hit the exception above.

我已经google了这个异常,看到有同样问题但没有看到任何解决方案的人。

I've googled the exception and saw someone having the same issues but didn't see any resolutions.

我的下一步是简化托管对象和关系这个错误停止并从那里构建隔离问题的点。最后一种方法是将Core Data删除并直接存储到sqllite中。

My next step was going to be simplifying the managed objects and relationships to a point where this error stops and build from there to isolate the issue. The last resort is to ditch Core Data and just directly store into sqllite.

感谢您的帮助!

推荐答案

我有同样的问题。它适用于较小的数据集,但对于较大的集合,我得到_referenceData64只定义为抽象类错误。我的模型中没有抽象实体。

I have the same issue. It works for smaller data sets, but for larger sets I get "_referenceData64 only defined for abstract class" errors. There's no abstract entities in my model.

编辑:

我想我已经解决了。我的情况下的问题是我的部分重复线程的混乱。以下是我修复它的指南:

I think I got this resolved. The issue in my case was a confusion on my part re threads. Here's the guidelines I followed to fix it:


  1. 我在一个线程中解析XML数据。在启动所述线程时,使用与主线程的NSManagedObjectContext相同的持久存储协调器来创建新的NSManagedObjectContext。

  2. 您在线程中创建的任何新对象都应该为线程的NSManagedObjectContext。如果你必须从主线程的NSManagedObjectContext中复制对象,通过ID复制。 Ie

    NSManagedObjectID * objectID = [foo objectID];

    FooClass * newFoo = [(FooClass *)[threadManagedObjectContext objectWithID:objectID] retain]

  3. 完成解析后,您需要保存对线程的NSManagedObjectContext所做的更改。您必须锁定持久存储协调器。我使用了以下(不完整的代码):

`

 - (void)onFinishParsing {  
  // lock the store we share with main thread's context  
  [persistentStoreCoordinator lock];  

  // save any changes, observe it so we can trigger merge with the actual context  
  @try {  
    [threadManagedObjectContext processPendingChanges];  
  }  
  @catch (NSException * e) {  
    DLog(@"%@", [e description]);  
    [persistentStoreCoordinator unlock];  
  }  
  @finally {  
    // pass  
  }  

  NSNotificationCenter *dnc = [NSNotificationCenter defaultCenter];  
  [dnc addObserver:self selector:@selector(threadControllerContextDidSave:) name:NSManagedObjectContextDidSaveNotification object:threadManagedObjectContext];  
  @try {  
    NSError *error;  
    if (![threadManagedObjectContext save:&error]) {  
      DLog(@"%@", [error localizedDescription]);  
      [persistentStoreCoordinator unlock];  
      [self performSelectorOnMainThread:@selector(handleSaveError:) withObject:nil waitUntilDone:NO];  
    }  
  } @catch (NSException *e) {  
    DLog(@"%@", [e description]);  
    [persistentStoreCoordinator unlock];  
  } @finally {  
    // pass  
  }  
  [dnc removeObserver:self name:NSManagedObjectContextDidSaveNotification object:threadManagedObjectContext];  

  [self performSelectorOnMainThread:@selector(parserFinished:) withObject:nil waitUntilDone:NO];  
}  

// Merging changes causes the fetched results controller to update its results  
- (void)threadControllerContextDidSave:(NSNotification*)saveNotification {  
  // need to unlock before we let main thread merge  
  [persistentStoreCoordinator unlock];  
  [self performSelectorOnMainThread:@selector(mergeToMainContext:) withObject:saveNotification waitUntilDone:YES];  
}  

- (void)mergeToMainContext:(NSNotification*)saveNotification {  
  NSError *error;  
  [managedObjectContext mergeChangesFromContextDidSaveNotification:saveNotification];  
  if (![managedObjectContext save:&error]) {  
    DLog(@"%@", [error localizedDescription]);  
    [self handleSaveError:nil];  
  }  
}  

`

这篇关于Core Data中的cryptic错误:NSInvalidArgumentException,reason:referenceData64仅为抽象类定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 01:10