seen others은 managedObjectContext 외부에서 NSManagedObject를 사용하는 방법을 묻습니다. 모두가 그렇다고 말하면서는 안된다고 말하지만 대신해야 할 일에 대한 정보를 찾을 수 없습니다.managedObjectContext 외부의 NSManagedObject
필자는 본질적으로 내 NSManagedObject에 설정된 데이터로 두 가지 다른 작업을 수행하려고합니다. 을 persistentStore에 저장하고 원격 서버로 보내려고합니다. 내 아이디어 alloc/init 내 NSManagedObject의 인스턴스, 해당 속성을 채 웁니다 다음 그 속성을 해당 속성을 제대로 전달 된 수 NSManagedObject, 전달할 수 및 다음 다른 함수에 전달하는 것입니다 책임을 질 것입니다 서버에 데이터를 보내기위한 것. 코드에서
: 당신이 기대하는 바와 같이,이 내가 propertyA을 설정하려고 두 번째 줄에 실패
// in my view controller Event *event = [Event alloc] init]; event.propertyA = @"foo"; event.propertyB = @"bar"; [self logEvent:event]; [self sendEvent:event]; ----------------------------------- // method in view controller - (void)logEvent(Event *)event { // my thought was to take the event that I manually created, and use it to // set the properties on the Event object in the managedObjectContext. Event *eventEntity = [NSEntityDescription insertNewObjectForEntityForName:@"Event" inManagedObjectContext:self.managedObjectContext]; eventEntity.propertyA = event.propertyA; eventEntity.propertyB = event.propertyB; ... [self.managedObjectContext save:&error]; } - (void) sendEvent:(Event *)event { // send exact same event properties to remote server }
(이벤트 NSManagedObject의 서브 클래스입니다).
대신 무엇을해야합니까? 내 NSManagedObject 객체와 동일한 속성/속성 인 을 가진 NSObject의 바닐라 서브 클래스를 생성해야합니까? 제안 된 솔루션은 NSInMemoryStoreType에 대한 이야기로 연결되었지만, 실제로 내가 원하는 모든 것이 객체를 전달하는 편리한 방법 일 때 잔인한 것으로 보입니다. 이 경우에는 객체가 NSManagedObject이므로, 내가 할 수있는 일이 제한적입니다.
"이 문제가 발생했습니다"라고 말하면 정확히 무엇이 발생하고 있습니까? – Anomie
'NSInvalidArgumentException'과 함께 실패합니다 : '- [Event setTimestamp :] : @syntehesize [d] 대신 모든 속성 @dynamic이 인스턴스 0x1c0d50으로 전송되었습니다. – djibouti33