문제

그래서 왜 이런 오류가 발생하는지 전혀 모르겠습니다.오류 메시지는 다음과 같습니다.

* 포착되지 않은 예외 'RLMException'으로 인해 앱 종료, 이유:'쓰기 트랜잭션 외부에서 객체를 수정하려고 시도 - 먼저 RLMREALM 인스턴스에서 beginWriteTransaction을 호출하십시오.' * 첫 번째 호출 스택 발생:(0x2f7b0f83 0x39f61ccf 0xc46ef 0xc3c23 0xc0c9d 0xb3e73 0x3a449833 0x3a449d 0x3a44a297 0x3a45c88d 0x3a45cb21 0x3a58bd3 0x3a5ba9). .dylib :NSException 유형의 포착되지 않은 예외로 종료

그리고 이 코드를 실행하는 동안 발생합니다.

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    UITextField * alertTextField = [alertView textFieldAtIndex:0];
    if (![self.chatSession.theirAlias isEqualToString:alertTextField.text]) {
        self.sender = alertTextField.text;
        dispatch_queue_t queue = ((AppDelegate *)[UIApplication sharedApplication].delegate).queueForWrites;
        dispatch_async(queue, ^{
            [[RLMRealm defaultRealm] beginWriteTransaction];
            self.chatSession.myAlias = alertTextField.text; // This is the line where the error is thrown
            [[RLMRealm defaultRealm] commitWriteTransaction];
        });
    } else {
        [self promptForAliasAfterRejection];
    }
}

쓰기 트랜잭션 내부에 글을 쓰고 있다는 것은 매우 분명합니다.Realm의 버그인가요?아니면 제가 뭔가를 놓치고 있는 걸까요...?

도움이 되었습니까?

해결책

그만큼 beginWriteTransaction 그리고 commitWriteTransaction 수정 중인 객체가 있는 동일한 영역에서 호출되어야 합니다.전화할 때마다 [RLMRealm defaultRealm], 당신은 새로운 영역을 얻고 있습니다.이것은 그 안에 있는 것과 같은 영역이 아닐 것입니다. self.chatSession.이 문제를 해결하려면 먼저 다음 사항을 확인하세요. self.chatSession의 영역은 귀하의 영역과 동일한 대기열에 있습니다. queueForWrites (내 추측으로는 self.chatSessionRLMObject, 물론).그런 다음 대신 블록 내부에서 다음을 수행하십시오.

[self.chatSession.realm beginWriteTransaction];
self.chatSession.myAlias = alertTextField.text;
[self.chatSession.realm commitWriteTransaction];
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top