0

개체를 저장할 때 MagicalRecord를 사용하는 데 문제가 발생했습니다.Exec가 개체를 저장할 때 MagicalRecord를 사용하여 액세스 할 수 없음

사용하여 상황에 맞는 절약 :

//get correct order based on indexPath 
Order *orderToComplete = [self objectInOrdersAtIndex:indexPath.section]; 
//set order as completed 
[MagicalRecord saveWithBlock:^(NSManagedObjectContext *localContext) 
{ 
    Order *localOrder = [orderToComplete inContext:localContext]; 
    [localOrder setIsCompletedValue:YES]; 
}completion:^(BOOL success, NSError *error) 
{ 
    if(success) 
     NSLog(@"You successfully saved your context."); 
    else 
     NSLog(@"Error saving context: %@", error.description); 
}]; 

을하지만 여전히 무작위로 충돌이 원인이 내가 사용했던 [[self MR_defaultContext] mergeChangesFromContextDidSaveNotification:notification];

다른 방법에 내 응용 프로그램 EXEC_BAD_ACCESS와 무작위로 충돌을 일으킬

- (void)saveContext { 
    [[NSManagedObjectContext defaultContext] saveToPersistentStoreWithCompletion:^(BOOL success, NSError *error) { 
     if (success) { 
      NSLog(@"You successfully saved your context."); 
     } else if (error) { 
      NSLog(@"Error saving context: %@", error.description); 
     } 
    }]; 
} 

을 .

내 응용 프로그램이 다중 스레드 응용 프로그램이 아닙니다. 여기에 있습니다 : enter image description here

누구 아이디어가 있습니까?

+0

같은 문제가 있습니다. 해결 했니? –

답변

0

내 문제를 해결할 수 있습니다. 그러나 정확한 이유를 찾지 못했습니다.

단계는 대상 방법

  1. 분명 모든 코드를 따라 그냥 객체를 생성하고 저장해야합니까? 저장합니까? 그렇다면 :
  2. 코드를 추가하고 단계별 테스트를 통해 코드에서 어디에서 managedObjectStore가 불일치 상태가되는지 확인할 수 있습니다. 나를 위해 그것은 대리인 메서드를 호출했기 때문입니다. 위임 메서드 호출 후 [NSManagedObjectContext saveContext]을 입력했습니다. 고정식

메신저 버전 2.2를 사용합니다. 어디에서 문제가 발생하는지 알 수 있었지만 그 이유를 알 수 없었습니다! 하지만 여기 나와 있습니다. 새 항목이 네트워크에서 장치로 푸시됩니다. 따라서 첫 번째 레코드 인 경우 셀이 자동으로 선택되어야합니다. 그런 다음 detailsView 컨트롤러를 호출하여 setItems를 위임하여 해당 항목을 업데이트합니다. 그 후 KVO는 변경 사항에 대해 알리고 tableView를 업데이트하려고 시도합니다 : 레코드가 없다고 상상하면 새 항목이 장치에 푸시되고 해당 하위 항목이 대리자 메서드를 통해 detailsViewController에 추가됩니다.

self.subItems = subItems;

landscape

단계 : 2 저장 컨텍스트

가 대리자 메서드는 모든 푸시에 두 번 호출 1 업데이트보기. KVO가 subItems NSKeyValueChangeSetting에 변경이 있음을 알립니다. 두 번째 푸시에 두 번째 푸시가 새 하위 항목을 포함하면 KVO가 처음으로 알림 항목에 삽입됩니다. subItemsNSKeyValueChangeInsertion에 삽입 된 후 대리인 메서드 호출이 두 번 호출되면 KVO에 변경이 있음을 알립니다. NSKeyValueChangeSetting. 테이블 응용 프로그램 충돌을 다시로드 한 후이 단계에서!

NSNumber *kind = [change objectForKey:NSKeyValueChangeKindKey]; 
     //if we are setting new items to the items array; i.e. when we select a new row 
     if ([kind integerValue] == NSKeyValueChangeSetting) { 
      // adding the all the new items at top of the tableView 
      NSArray *newItems = [change valueForKey:@"new"]; 
      [self.tableView reloadData]; 

     } 
     //if we are adding one new order to the orders array 
     else if ([kind integerValue] == NSKeyValueChangeInsertion) 
     { 
      // adding the new order at top of the tableView 
      [self.tableView insertSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationTop]; 
     } 

마침내이 충돌을 해결하기 위해 한 번 호출 된 대리자를 사용해 보았습니다. 하지만 왜 위의 오류가 발생하는지 이해할 수 없었습니다!

https://github.com/magicalpanda/MagicalRecord/issues/877