Home > Back-end >  Sometime NSManagedobject object become fault when passing object from one controller to another, is
Sometime NSManagedobject object become fault when passing object from one controller to another, is

Time:09-08

First controller

OptiiMobileTaskDetailViewController *taskDetailVC = (OptiiMobileTaskDetailViewController *)segue.destinationViewController;
[taskDetailVC setTask:task];

 

Second Controller

-(void) setTask:(Task *)task {
    _task = task;
}

This code working properly but sometime when we use task object in second VC we got Fault object so is there any other way to pass NSManagedobject between view controllers

CodePudding user response:

 (instancetype) taskWithTaskID:(NSNumber *)taskID {
    
    Task *task = [self getManagedObjectForKey:@"taskID" keyValue:taskID];
    if (!task) {
        
        //Create task
        task = [[OptiiMobileDataStore sharedInstance] createNewObjectNamed:NSStringFromClass([self class])];
        task.taskID = taskID;
        [[OptiiMobileDataStore sharedInstance] insertObject:task];
    }
    
    return task; }

and get the new copy of data just before it is get default

    _task = [Task taskWithTaskID:self.taskID];
  • Related