나는이 간략한 내용을 유지하려고 노력할 것이다. 그러나 기본적으로 특정 모드에서 위치 및 기타 데이터를 거의 연속적으로 기록 할 수있는 앱을 사용하고있다. AVFoundation)에 저장하고 Core Data에 저장하십시오. 의심스러워서이 모든 것을 스레드해야 할 필요가 있음을 발견했습니다. 그렇지 않으면 UI가 매우 느려집니다.코어 데이터 멀티 스레딩 - 내가 뭘 잘못하고 있니?
내가 코어 데이터를 동시성과 결합 시키려고 한 적은 한번도 없었습니다. 그래서 최선을 다해 읽었습니다. 내가 뭘해야 하는지를 이해하고있는 것처럼 느껴지지만, 누군가 옳은 이유로 그것을 이해합니다. 이 오류로 인해 충돌이 발생합니다. "서로 다른 컨텍스트의 개체간에"managedDataPoint "관계를 설정하려는 잘못된 시도.이게 무슨 뜻인지는 알지만, 아래에있는 내용은이 문제를 피할 것이라고 생각했습니다 (읽은 내용을 따르고 있습니다). . 내가 메인 컨텍스트에서 객체 ID 참조를 얻은 다음, 객체에 대한 새로운 참조를 가져 와서 "temp"컨텍스트에 전달하는 데 사용합니다 ...하지만 핵심 데이터로 작동하지 않습니다. 컨텍스트 (?)에 걸쳐 관계를 만들려고. 어떤 도움을 주셔서 감사이. 감사합니다!
-(void)snapPhotoForPoint:(ManagedDataPoint*)point
{
if (!_imageCapturer)
{
_imageCapturer = [[ImageCapturer alloc] init];
}
if (!_tempContext) {
_tempContext = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSPrivateQueueConcurrencyType];
_tempContext.parentContext = self.managedObjectContext;
}
__block NSManagedObjectID* pointID = [point objectID];
[_tempContext performBlock:^{
NSError *error = nil;
Photo *newPhoto = [NSEntityDescription insertNewObjectForEntityForName:@"Photo" inManagedObjectContext:_tempContext];
UIImage *image = [_imageCapturer takePhoto];
newPhoto.photoData = UIImageJPEGRepresentation(image, 0.5);
ManagedDataPoint *tempPoint = (ManagedDataPoint*)[self.managedObjectContext objectWithID:pointID];
newPhoto.managedDataPoint = tempPoint; // *** This is where I crash
if (![_tempContext save:&error]) { // I never get here.
DLog(@"*** ERROR saving temp context: %@", error.localizedDescription);
}
}];
}
https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/CoreData/Concurrency.html –