问题
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