使用MagicalRecord导入数据 [英] Importing Data using MagicalRecord
问题描述
我使用MagicalRecord从plist导入数据。我使用的代码少导入,如本教程中所述此问题。
MR_importFromArray:
正在使用 MR_saveWithBlock:
code> saveWithBlockAndWait:解决了问题。 错误修复
I'm using MagicalRecord to import data from plist. I'm using code less import as explained in this tutorial Importing Data Made Easy.
I have two entities Manufacturer and Car, they have one to many and one to one relation respectively.
Plist structure
This import work fine
NSArray *manufacturers = ...
[MagicalRecord saveWithBlock:^(NSManagedObjectContext *localContext) {
[manufacturers enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
[Manufacturer MR_importFromObject:obj inContext:localContext];
}];
} completion:^(BOOL success, NSError *error) {
}];
But this is not getting imported
[MagicalRecord saveWithBlock:^(NSManagedObjectContext *localContext) {
[Manufacturer MR_importFromArray:manufacturers inContext:localContext];
} completion:^(BOOL success, NSError *error) {
}];
Any explanation would be highly appreciated.
EDIT : Log of manufacturers array
[
{
"Cars": [
{
"CarID": 1,
"Name": "Civic"
},
{
"CarID": 2,
"Name": "Jazz"
},
{
"CarID": 3,
"Name": "City"
}
],
"ManufacturerID": 1,
"Name": "Honda"
}
]
The issue seems to be like a bug in MagicalRecord, found an open bug filed for this issue.
MR_importFromArray:
was using MR_saveWithBlock:
replacing with saveWithBlockAndWait:
solves the issue. Bug Fix
这篇关于使用MagicalRecord导入数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!