Importing Data using MagicalRecord

北战南征 提交于 2019-12-06 02:49:45

问题


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"
    }
]

回答1:


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



来源:https://stackoverflow.com/questions/16209985/importing-data-using-magicalrecord

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!