Question

Currently working with core data,

Below is my Data Model:

WorkoutType (One to Many workouts with WorkoutSet)
WorkoutSet  (One to Many days with WorkoutDay)
WorkoutDay  (One to Many exercises with WorkoutExercise
WorkoutExercise

The data for all 4 are displayed through 4 tableviews.

Im using FetchedResultsController and all is working correctly.

My next problem is that i am passing from the workoutExerciseTableViewController to another ViewController and wandering how I can pass All the data across to this view controller. such as i will need access to the workoutType, workoutSet and workoutDay data that was selected through to reach to the workoutExercise data.

Below is the fetchedResultsController in my WorkoutExerciseTableViewController:

-(void)fetchWorkoutExercises
{
    NSFetchRequest *fetchRequest = [NSFetchRequest     fetchRequestWithEntityName:@"WorkoutExercise"];
    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"workoutDay = %@",     self.workoutDay];
    NSSortDescriptor *sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"exerciseName" ascending:YES];
    [fetchRequest setSortDescriptors:@[sortDescriptor]];
    [fetchRequest setPredicate:predicate];
    self.fetchedResultsController = [[NSFetchedResultsController alloc]
                                 initWithFetchRequest:fetchRequest managedObjectContext:self.managedObjectContext
                                 sectionNameKeyPath:nil cacheName:nil];
    //self.fetchedResultsController.delegate = self;
    NSError *error;
    if (![self.fetchedResultsController performFetch:&error])
    {
        NSLog(@"Fetch failed: %@", error);
    }

}

Thanks for any help in advance :)

Was it helpful?

Solution

You need only to pass the selected WorkoutExercise •exercise to the next view controller, because the other data can be accessed from there

WorkoutDay *day = exercise.workoutDay;
WorkoutSet *set = day.workoutSet;
WorkoutType *type = set.workoutType;

using the inverse relationships.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top