mac mini和imac编译之间的区别

时间:2011-05-19 15:49:37

标签: cocoa xcode

我正在我的iMac上构建并进行所有应用程序测试。一切都很好。 当我尝试在mac mini(服务器版)上使用相同的应用程序时,我有时会出错:

19.05.11 16:14:56 snowServer[57705] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Failed to process pending changes before save.  The context is still dirty after 100 attempts.  Typically this recursive dirtying is caused by a bad validation method, -willSave, or notification handler.'

    *** Call stack at first throw:
    (
    0   CoreFoundation                      0x96c5a6ba __raiseError + 410
    1   libobjc.A.dylib                     0x91fb4509 objc_exception_throw + 56
    2   CoreData                            0x9719ef91 -[NSManagedObjectContext(_NSInternalChangeProcessing) _prepareForPushChanges:] + 481
    3   CoreData                            0x9719e915 -[NSManagedObjectContext save:] + 453
    4   snowServer                          0x00031da4 -[GetExternalInfo finalSave:] + 116
    5   snowServer                          0x00032c2d -[GetExternalInfo main] + 2349
    6   Foundation                          0x95df31bb -[__NSOperationInternal start] + 705
    7   Foundation                          0x95ee3d57 __doStart2 + 89
    8   libSystem.B.dylib                   0x9144e024 _dispatch_call_block_and_release + 16
    9   libSystem.B.dylib                   0x914402f2 _dispatch_worker_thread2 + 228
    10  libSystem.B.dylib                   0x9143fd81 _pthread_wqthread + 390
    11  libSystem.B.dylib                   0x9143fbc6 start_wqthread + 30
    )

我不熟悉mac模型之间的差异,但在这种情况下有人可以提出建议吗?每个型号兼容性的一些提示和技巧。

以下是我从NSOperation子类中保存的方法:

managedObjectContext = [[NSManagedObjectContext alloc] init];
[managedObjectContext setPersistentStoreCoordinator:[appDelegate persistentStoreCoordinator]];

[managedObjectContext setUndoManager:nil];

// Register context with the notification center
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; 
[nc addObserver:self
       selector:@selector(mergeChanges:) 
           name:NSManagedObjectContextDidSaveNotification
         object:managedObjectContext];

- (void)mergeChanges:(NSNotification *)notification;
{
     NSManagedObjectContext *mainContext = [appDelegate managedObjectContext];

// Merge changes into the main context on the main thread
    [mainContext   performSelectorOnMainThread:@selector(mergeChangesFromContextDidSaveNotification:)   
                              withObject:notification
                           waitUntilDone:YES];
}

最后:

[self finalSave:managedObjectContext];

ANSWER

这很奇怪,但这个问题解决了问题:

 dispatch_async(dispatch_get_main_queue(), ^(void) { [self finalSave:managedObjectContext]; });

奇怪,因为我为所有操作创建了新的moc。

0 个答案:

没有答案