Objective c CoreData—ChildContext保存推送父上下文

Objective c CoreData—ChildContext保存推送父上下文,objective-c,core-data,Objective C,Core Data,问题是: NSManagedObjectContext* mainContext = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSMainQueueConcurrencyType]; [context setPersistentStoreCoordinator:coordinator]; NSManagedObjectContext* childContext = [[NSManagedObjectContext all

问题是:

NSManagedObjectContext* mainContext = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSMainQueueConcurrencyType];

[context setPersistentStoreCoordinator:coordinator];

NSManagedObjectContext* childContext = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSPrivateQueueConcurrencyType];

[childContext setParentContext:mainContext];

Amount* amount = [[Amount alloc] initWithEntity:[NSEntityDescription entityForName:@"Amount" inManagedObjectContext:context] insertIntoManagedObjectContext:nil];

amount.xyz = @"String";
[childContext insertObject:amount];

/*
(lldb) po [childContext insertedObjects]
{(
    <Amount: 0x7fc3635b90f0> (entity: Amount; id: 0x7fc3635b7a00 <x-coredata:///Amount/t3176AD5B-914D-469D-AFCE-21D5D679E3652> ; data: {
    xyz = String;
})
)}
*/
NSError* error = nil;
[childContext save:&error];
/*
(lldb) po [mainContext insertedObjects]
{(
    <Amount: 0x7fc3634701e0> (entity: Amount; id: 0x7fc3635b7a00 <x-coredata:///Amount/t3176AD5B-914D-469D-AFCE-21D5D679E3652> ; data: {
    xyz = nil;
})
)}
*/