Search code examples
iosobjective-ccore-datansuserdefaults

Sometime NSManagedobject object become fault when passing object from one controller to another, is there any way to pass object as a value type objC


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


Solution

  • +(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];