核心数据后台保存不起作用

时间:2013-01-14 07:16:22

标签: ios core-data nsmanagedobjectcontext

我更改了数据(按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);
 }
}

0 个答案:

没有答案