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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With