objectId
및 objectName
특성을 가진 개체가 있습니다. 핵심 데이터의 deleteObject
함수를 사용하여 항목을 삭제하고 컨텍스트를 저장하면 개체를 술어로만 사용했지만 개체의 값이 null입니다. 여기 내 코드가있다.Core Data 저장 컨텍스트 뒤에 삭제되지 않은 개체 값이 null입니다.
NSLog(@"%@", self.theObject.name); // it returns the object's name
NSError *error = nil;
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] initWithEntityName:@"MyEntity"];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"objectId==%@", self.theObject.objectId];
fetchRequest.predicate = predicate;
NSArray *myObjects = [context executeFetchRequest:fetchRequest error:&error];
for (MyClass *myObject in myObjects) {
[context deleteObject:myObject];
}
if (![context save:&error]) {
NSLog(@"Could not delete! %@ %@", error, [error localizedDescription]);
} else {
NSLog(@"%@", self.theObject.name); // it returns null
}
코어 데이터의 기본 동작입니까, 아니면 놓친 부분이 있습니까? 조건 자로 만 사용했을 때 theObject
의 값이 null 인 이유는 무엇입니까? 주석
theObject
에 기초
편집 방법은 prepareForSegue
내의 상위 뷰 컨트롤러로부터 설정한다.
destinationViewController.theObject = self.theObjectsArray[indexPath.row];
나는 viewDidLoad
에 theObject
값을 기록하며 성공적으로 설정되었다.
theObject 인 objectID ...가있는 컨텍스트에서 개체를 삭제하는 것처럼 보입니다. – Volker
@Volker 방금 술어에 대한 객체의 ID를 사용하고 myObjects 배열에 요청을 채 웁니다. myObject (MyClass) 만 삭제했지만 context를 저장 한 후에 theObject의 값은 null입니다. 너무 혼란 스럽네. 추신 myObject와 theObject는 다른 클래스입니다. –
그래서 Object가 null을 표시하면 몇 가지 이유가 있어야하며 마술처럼 생기지는 않습니다. 어쩌면 당신은 theObject를 만드는 방법에 대한 더 자세한 정보를 제공 할 수 있습니다. 술어에서 값을 사용하면 NULL 값으로 재설정되지 않습니다. – Volker