注意,我已经查看了以下帖子:(Stack overflow issue 1 Stack overflow issue 2
我在我的应用中看到了以下崩溃堆栈:
2 libsystem_c.dylib 0x32bc87ec _sigtramp + 48
3 CoreData 0x361a2e70 -[NSSQLCore _populateRowForOp:withObject:] + 2716
4 CoreData 0x36194ca2 -[NSSQLCore recordUpdateForObject:] + 130
5 CoreData 0x3619defc -[NSSQLCore recordChangesInContext:] + 600
6 CoreData 0x3619bfae -[NSSQLCore saveChanges:] + 286
7 CoreData 0x360f425e -[NSSQLCore executeRequest:withContext:error:] + 946
8 CoreData 0x360f3336 -[NSPersistentStoreCoordinator executeRequest:withContext:error:] + 1130
9 CoreData 0x3615b286 -[NSManagedObjectContext save:] + 522
10 MyCrashingApp 0x000aa040 -[DisplayModelMgr saveDisplayModel:forDate:] (DisplayModelMgr.m:182)
这是一个sigsegv所以,它不能通过@try捕获.. @ catch。 这种情况很少发生,所以我很好奇它是否是一种竞争条件,在删除和添加之间的注释中都有注明。
通话代码为:
- (void) saveDisplayModel:(DisplayModel *)model forDate:(NSDate *)date
{
if (model == nil || date == nil)
return;
[log debug:[model description]];
[log debug:@"DMM: saveDisplayModel: %@ lastSyncDate: %@",date, [model lastSyncDate]];
NSFetchRequest *request = [[[NSFetchRequest alloc] init] autorelease];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"MyDisplayModel" inManagedObjectContext:self.context];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(requestDate == %@)", date];
[request setPredicate:predicate];
[request setFetchLimit:1];
[request setEntity:entity];
NSError *error = nil;
NSArray *mutableFetchResults = [self.context executeFetchRequest:request error:&error];
if (mutableFetchResults != nil) {
[log debug:@"DMM: mutableFetchResults:count %i",[mutableFetchResults count]];
NSDate *sDate = [[model.lastSyncDate copy] autorelease];
NSDate *timestamp = [NSDate date];
MyDisplayModel *coreDataModel = nil;
if([mutableFetchResults count] > 0) {
coreDataModel = [mutableFetchResults objectAtIndex:0];
[coreDataModel setSyncDate:sDate];
[coreDataModel setTimeStamp:timestamp];
[coreDataModel setRequestDate:date];
if(model.entries != nil && [model.entries count] > 0) {
for(MyDisplayModelValue *existingVal in coreDataModel.values) {
[self.context deleteObject:existingVal];
}
}
[coreDataModel setValues:nil]; // race condition?
} else {
coreDataModel = [NSEntityDescription
insertNewObjectForEntityForName:@"MyDisplayModel"
inManagedObjectContext:self.context];
[coreDataModel setSyncDate:sDate];
[coreDataModel setTimeStamp:timestamp];
[coreDataModel setRequestDate:date];
}
for(DisplayModelEntry *dmv in [model.entries allValues]) {
MyDisplayModelValue *newDashModelVal = [NSEntityDescription
insertNewObjectForEntityForName:@"MyDisplayModelValue"
inManagedObjectContext:self.context];
[newDashModelVal setType:[NSNumber numberWithInt:dmv.type]];
[newDashModelVal setActual:[NSNumber numberWithInt:dmv.actual]];
[newDashModelVal setSource:[NSNumber numberWithInt:dmv.source]];
[newDashModelVal setTarget:[NSNumber numberWithInt:dmv.target]];
[newDashModelVal setMymodel:coreDataModel];
[[coreDataModel mutableSetValueForKey:@"values"] addObject:newDashModelVal]; // create new if missing?
}
NSError *error;
if (![self.context save:&error]) {
[log error:@"Error Saving Dashbaord Cache: %@",[error description]];
}
[self.context refreshObject:coreDataModel mergeChanges:NO];
}
}
对此的任何指导都热烈赞赏。评论请求的澄清将很快得到回复。