MagicalRecord过早触发完成块

时间:2015-05-06 13:42:01

标签: objective-c core-data magicalrecord

昨天我asked an almost similar question here on stackoverflow,它确实解决了我的问题。 Hoverever现在我又遇到了同样的问题,但随着新的实施。在添加了一些要导入的数据后,我现在又遇到了同样的问题。但是这次看起来saveAndWait的完成块在完成之前就被触发了。

这是JSON api包含更多数据,而不是代码本身。

这是我目前的代码:

[MagicalRecord saveWithBlock:^(NSManagedObjectContext *localContext) {

    NSDictionary *jsonData = [responseObject valueForKey:@"responses"];
    [User importFromObject:jsonData inContext:localContext];

    NSArray *orders = [responseObject valueForKeyPath:@"responses.orders"];
    [Order importFromArray:orders inContext:localContext];

} completion:^(BOOL success, NSError *error) {
    if(error) {
        NSLog(@"Failed to save data");
        return;
    }
    NSLog(@"Saving done.");
    successful(@"Some text");
}];

如上所述,代码中没有任何变化,只有收到的数据。

日志显示在完成所有节省之前调用“已完成保存”。这是我导入数据或保存数据的唯一地方。

2015-05-06 14:55:57.261 xxxx[43159:9057742] +[NSManagedObjectContext(MagicalRecord) MR_contextWithStoreCoordinator:](0xfeea04) -> Created Context UNNAMED
2015-05-06 14:55:57.262 xxxx[43159:9057742] +[NSManagedObjectContext(MagicalRecord) MR_setRootSavingContext:](0xfeea04) Set Root Saving Context: <NSManagedObjectContext: 0x7ae6cb20>
2015-05-06 14:55:57.263 xxxx[43159:9057742] +[NSManagedObjectContext(MagicalRecord) MR_newMainQueueContext](0xfeea04) Created Main Queue Context: <NSManagedObjectContext: 0x7ae73ee0>
2015-05-06 14:55:57.263 xxxx[43159:9057742] +[NSManagedObjectContext(MagicalRecord) MR_setDefaultContext:](0xfeea04) Set Default Context: <NSManagedObjectContext: 0x7ae73ee0>
2015-05-06 14:55:58.915 xxxx[43159:9057742] POST 'xxxx'
2015-05-06 14:55:59.939 xxxx[43159:9057742] 200 'xxxx' [1.0249 s]
2015-05-06 14:55:59.957 xxxx[43159:9057742] POST 'xxxx'
2015-05-06 14:56:00.702 xxxx[43159:9057742] 200 'xxxx' [0.7454 s]
2015-05-06 14:56:10.534 xxxx[43159:9058195] -[NSManagedObjectContext(MagicalSaves) MR_saveWithOptions:completion:](0x7af24cb0) → Saving <NSManagedObjectContext (0x7af24cb0): *** UNNAMED ***> on *** BACKGROUND THREAD ***
2015-05-06 14:56:10.535 xxxx[43159:9058195] -[NSManagedObjectContext(MagicalSaves) MR_saveWithOptions:completion:](0x7af24cb0) → Save Parents? 1
2015-05-06 14:56:10.535 xxxx[43159:9058195] -[NSManagedObjectContext(MagicalSaves) MR_saveWithOptions:completion:](0x7af24cb0) → Save Synchronously? 0
2015-05-06 14:56:10.541 xxxx[43159:9058195] -[NSManagedObjectContext(MagicalRecord) MR_contextWillSave:](0x7af24cb0) Context UNNAMED is about to save. Obtaining permanent IDs for new 2 inserted objects
2015-05-06 14:56:10.750 xxxx[43159:9058195] -[NSManagedObjectContext(MagicalSaves) MR_saveWithOptions:completion:](0x7ae6cb20) → Saving <NSManagedObjectContext (0x7ae6cb20): *** BACKGROUND SAVING (ROOT) ***> on *** BACKGROUND THREAD ***
2015-05-06 14:56:10.750 xxxx[43159:9058195] -[NSManagedObjectContext(MagicalSaves) MR_saveWithOptions:completion:](0x7ae6cb20) → Save Parents? 1
2015-05-06 14:56:10.750 xxxx[43159:9058195] -[NSManagedObjectContext(MagicalSaves) MR_saveWithOptions:completion:](0x7ae6cb20) → Save Synchronously? 0
2015-05-06 14:56:16.200 xxxx[43159:9058195] -[NSManagedObjectContext(MagicalRecord) MR_contextWillSave:](0x7ae6cb20) Context BACKGROUND SAVING (ROOT) is about to save. Obtaining permanent IDs for new 2 inserted objects
2015-05-06 14:56:16.232 xxxx[43159:9058195] __70-[NSManagedObjectContext(MagicalSaves) MR_saveWithOptions:completion:]_block_invoke21(0x7ae6cb20) → Finished saving: <NSManagedObjectContext (0x7ae6cb20): *** BACKGROUND SAVING (ROOT) ***> on *** BACKGROUND THREAD ***
2015-05-06 14:56:16.233 xxxx[43159:9057742] Saving done.
2015-05-06 14:56:16.233 xxxx[43159:9057742] All data has been setup sucessfully
2015-05-06 14:56:16.255 xxxx[43159:9057742] Perform Segue To LoginSucessSegue from LoginViewController
2015-05-06 14:56:36.208 xxxx[43159:9057742] No data found. Show pull down to refresh
2015-05-06 14:56:36.208 xxxx[43159:9057742] No data found. Show pull down to refresh
2015-05-06 14:56:36.210 xxxx[43159:9057742] No data found. Show pull down to refresh
2015-05-06 14:56:36.211 xxxx[43159:9057742] No data found. Show pull down to refresh
2015-05-06 14:56:45.083 xxxx[43159:9058146] -[NSManagedObjectContext(MagicalSaves) MR_saveWithOptions:completion:](0x7ae3b550) → Saving <NSManagedObjectContext (0x7ae3b550): *** UNNAMED ***> on *** BACKGROUND THREAD ***
2015-05-06 14:56:45.083 xxxx[43159:9058146] -[NSManagedObjectContext(MagicalSaves) MR_saveWithOptions:completion:](0x7ae3b550) → Save Parents? 1
2015-05-06 14:56:45.084 xxxx[43159:9058146] -[NSManagedObjectContext(MagicalSaves) MR_saveWithOptions:completion:](0x7ae3b550) → Save Synchronously? 0
2015-05-06 14:56:45.084 xxxx[43159:9058146] -[NSManagedObjectContext(MagicalRecord) MR_contextWillSave:](0x7ae3b550) Context UNNAMED is about to save. Obtaining permanent IDs for new 9 inserted objects
2015-05-06 14:56:45.087 xxxx[43159:9058146] -[NSManagedObjectContext(MagicalSaves) MR_saveWithOptions:completion:](0x7ae6cb20) → Saving <NSManagedObjectContext (0x7ae6cb20): *** BACKGROUND SAVING (ROOT) ***> on *** BACKGROUND THREAD ***
2015-05-06 14:56:45.087 xxxx[43159:9058146] -[NSManagedObjectContext(MagicalSaves) MR_saveWithOptions:completion:](0x7ae6cb20) → Save Parents? 1
2015-05-06 14:56:45.091 xxxx[43159:9058146] -[NSManagedObjectContext(MagicalSaves) MR_saveWithOptions:completion:](0x7ae6cb20) → Save Synchronously? 0
2015-05-06 14:56:45.093 xxxx[43159:9060610] -[NSManagedObjectContext(MagicalRecord) MR_contextWillSave:](0x7ae6cb20) Context BACKGROUND SAVING (ROOT) is about to save. Obtaining permanent IDs for new 9 inserted objects
2015-05-06 14:56:45.096 xxxx[43159:9060610] __70-[NSManagedObjectContext(MagicalSaves) MR_saveWithOptions:completion:]_block_invoke21(0x7ae6cb20) → Finished saving: <NSManagedObjectContext (0x7ae6cb20): *** BACKGROUND SAVING (ROOT) ***> on *** BACKGROUND THREAD ***

是不是因为我不允许导入和保存saveWithBlock中的多个实体或者正在发生什么? - 我无法弄明白。

1 个答案:

答案 0 :(得分:1)

解决方案是将MagicalRecord更新为最新的测试版。在问我的项目是在2.2版本上运行的问题(一个“稳定”版本),现在它在v2.3.0-beta 5,巫婆解决了我的问题。

相关问题可在此处找到:https://github.com/magicalpanda/MagicalRecord/issues/1003