上传许多文件并保存在CoreData中

时间:2015-08-24 12:06:28

标签: ios objective-c core-data nsarray

使用API​​我得到500张图片,异步上传。然后我想将所有这些图片保存在CoreData中,但由于内存不足,应用程序崩溃了。

上传完成后,我致电方法createFromBlock

+(id)createFromBlock:(MRBlock *)block{
    ManagedBlock *item = [ManagedBlock MR_createInContext:DefaultContext];
    item.id = @(block.id);
    item.name = block.name;
    item.slidesInBlock =  @(block.slidesInBlock);

    item.sizeBlock = block.sizeBlock;
    item.desc = block.desc;
    item.imagePath = block.imagePath;
    item.image = [MRUtils transformedValue:block.image];
    item.price = block.price;
    int i = 0;
    ManagedItem *new = nil;
    for (MRItem *lol in block.items){
        NSLog(@"%i", i);
                        new = [ManagedItem createFromItem:lol];
                new.block = item;
                [item addItemsObject:new];
        new = nil;
        i++;
    }

    [DefaultContext MR_saveWithOptions:MRSaveSynchronously completion:nil];

    return item;
}

在foreach中,block.items应用程序崩溃了。大约在150-160个职位之后。

如果我评论new = [ManagedItem createFromItem:lol]; - app不要崩溃

+(id)createFromItem:(MRItem *)object{
    ManagedItem *item = [ManagedItem MR_createInContext:DefaultContext];
    item.id = @(object.id);
    item.title = object.title;
    item.detail = object.detail;
    item.imagePath = object.imagePath;
    item.image = [MRUtils transformedValue:object.image];
    return item;
}

0 个答案:

没有答案