我更改了我的数据(按 onBackgroundChange)并保存了它。我没有任何错误。在我的日志中,我看到“ _更改成功”状态。
-(IBAction) onBackgroundChange:(id)sender
{
AppDelegate *app = [[UIApplication sharedApplication] delegate];
NSManagedObjectContext *context = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSPrivateQueueConcurrencyType];
context.parentContext = app.managedObjectContext;
[context performBlock:^
{
NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:@"Thread"];
NSArray *array = [app.managedObjectContext executeFetchRequest:request error:nil];
if (array.count > 0)
{
Thread *thread = [array objectAtIndex:0];
thread.threadInfo = @"background thread";
NSLog(@"___ change successfully");
}
if (![context save:nil])
{
NSLog(@"thread save error");
}
}];
}
然后我停止了一个程序并再次运行。我的 onDescription 日志是
__ thread: main thread.
怎么了?
-(IBAction) onDescription:(id)sender
{
AppDelegate *app = [[UIApplication sharedApplication] delegate];
NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:@"Thread"];
NSArray *array = [app.managedObjectContext executeFetchRequest:request error:nil];
if (array.count > 0)
{
Thread *thread = [array objectAtIndex:0];
NSLog(@"__ thread: %@", thread.threadInfo);
}
}