IOS magical record create new entity and add to array not woking

为君一笑 提交于 2019-12-25 09:15:46

问题


Hi I'm working with Core Data and Magical Record. After receive JSON response from server. I want to create an entity, update its property and add to and array.

My code is

NSMutableArray *items = [NSMutableArray array];
NSManagedObjectContext *localContext = [NSManagedObjectContext MR_context];
Article *article = [Article MR_createEntityInContext:localContext];
[article setOrderingValue:idx];
[article updateWithApiRepresentation:articleJSON];
[items addObject:article];

I dont know why the above is not working (does not return correct items array). It's only work if I replace this line

Article *article = [Article MR_createEntityInContext:localContext];

with this line

Article *article = [[Article alloc] initWithEntity:[Article entityInManagedObjectContext:localContext] insertIntoManagedObjectContext:nil];

The main purpose is to return correct items array. Any help is much appreciate. Thanks

来源:https://stackoverflow.com/questions/38762689/ios-magical-record-create-new-entity-and-add-to-array-not-woking

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