Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Data Fault #106

Open
vishaldeshai opened this issue Sep 2, 2017 · 3 comments
Open

Data Fault #106

vishaldeshai opened this issue Sep 2, 2017 · 3 comments

Comments

@vishaldeshai
Copy link

Hello,

Why my data fault??
`[MagicalRecord saveWithBlock:^(NSManagedObjectContext * _Nonnull localContext) {
arr = [FEMDeserializer collectionFromRepresentation:[dict objectForKey:@"data"] mapping:[_LeadStatusList defaultMapping] context:localContext];
} completion:^(BOOL contextDidSave, NSError * _Nullable error) {
NSLog(@"%@",arr[0]);
_LeadStatusList *o = arr[0];
NSLog(@"%hd",o.interactionWith);
NSLog(@"%hd",o.outcomeID);
NSLog(@"%@",o.orderExpectedDate);
NSLog(@"%@",o.nextActionTime);
NSLog(@"%@",o.createdTime);
NSLog(@"%@",o.reminderTime);

                [_objLead insertObject:o inLeadStatusListAtIndex:0];
                [self.view makeToast:dict[@"message"]];
                [self.navigationController popViewControllerAnimated:YES];
            }];`

Save successfully and and arr contains 1 object that value of all parameters are not there.

thanks in advance.

@dimazen
Copy link
Contributor

dimazen commented Sep 2, 2017

Please, read about how nested contexts work. Also you might be interested in reading of the source code of the Magical Record in order to understand how does local saving works. It has nothing to do with the FastEaysMapping itself. Issue lies in your attempt to talk to the objects of the dead context.

@vishaldeshai
Copy link
Author

But can you tell me how i can prevent context dead??

@dimazen
Copy link
Contributor

dimazen commented Sep 5, 2017

@vishaldeshai MagicalRecord destroys localContext once it is done with the saving. Therefore you need to refetch your objects in the different context (referencing objectID is ok and won't cause fault), or to invoke saving of the context directly and not using a MR's API.

NSManagedObjectContext *context = taken from some api;

[context performBlockAndWait:^{
    array = [FEMDeserializer collectionFromRepresentation:[dict objectForKey:@"data"] mapping:[_LeadStatusList defaultMapping] context:context];
    [context MR_save ]; // choose your MR_save version. I do not remember exact naming
}];
// you're free to use your objects. But again, please pay attention on passing objects across contexts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants