I ended up finding this code on the stack. After setting up my fetchedResultsController correctly, I can use this code with a button or where ever it was necessary to calculate the total spaces for all games in my season.
int totalpassingyards = 0; for (NSManagedObject *object in [self.fetchedResultsController fetchedObjects]) { NSNumber *objectTotalPassingYardsNumber = [object valueForKey:@"passingyards"]; int objectTotalPassingYards = [objectTotalPassingYardsNumber intValue]; totalpassingyards = totalpassingyards + objectTotalPassingYards; } NSLog(@"Subtotal: %i", totalpassingyards);
My next step is to figure out how to calculate the total gaps for all seasons on my career list. This is how my relationship with coredata is set up.
Career > Season > Game (career stats) (season stats) (game stats) career stats = sum of season stats season stats = sum of game stats game stats = that individual games stats
I guess this will consist of creating two fetchedResultsControllers that have games, and one for spending seasons and then doing a certain type of nested loop to go through all of them. I will keep everyone informed.
If someone has a better way to do this, let me know, as I said that I am very new to this, so it really comes down to traces and mistakes, and although this may work, I understand that this is not the best way to do it's lol.
source share