I really need help with this, which I can't seem to figure out the solution to. I'm working on a quiz app; and when I try to save the user's score using my business object, I get an error that I've localized to the saveEntities method in mmBusinessObject as shown in the attachment. In the console, I get a whole bunch of messages, and the first message in that long list is as follows:
2014-08-18 14:35:55.211 sidepanel[28768:60b] CoreData: error: failed to resolve optimistic locking failure: optimistic locking failure with (null)
This is the code for my tableViewcontroller (MasterViewController1) where the error is occurring. The problem occurs at the second line that says [self.pugMenuBusinessObject saveEntities]; inside the method updateEntityGradeScore:from: where I try to save the self.pugMenuEntity after assigning the grade to its gradeScore attribute.
Any help or ideas on how to resolve this will be most appreciated.
//
// MasterViewController1.m
// sidepanel
//
// Created by Richard Tamesis on 7/24/14.
// Copyright (c) 2014 SkyPug. All rights reserved.
//
#import "MasterViewController1.h"
#import "PugMenuBusinessObject.h"
#import "PugMenuEntity.h"
@interface MasterViewController1 ()
@property (strong, nonatomic) PugMenuBusinessObject *pugMenuBusinessObject;
@property (strong, nonatomic) PugMenuEntity *pugMenuEntity;
@end
@implementation MasterViewController1
- (void)viewDidLoad
{
[super viewDidLoad];
[self selectTabBarItemImage:0 withImageFileName:@"PhysicalSelected"];
[self createBusinessObject];
}
#pragma mark - PUBLIC HELPER METHODS
- (void) createBusinessObject
{
self.pugMenuBusinessObject = [[PugMenuBusinessObject alloc] init];
self.fetchedResultsController = [self.pugMenuBusinessObject createAFetchedResultsControllerForEntity:@"PugMenuEntity" andSortDescriptorKey:@"section" ascending:YES];
}
// Delegate method from StartViewController
- (void) updateEntityGradeScore:(float)grade from:(StartViewController *)resultsVC
{
self.pugMenuEntity.gradeScore = grade;
[self.pugMenuBusinessObject saveEntities];
self.cell.detailTextLabel.text = [NSString stringWithFormat:@"%0.1f%%", self.pugMenuEntity.gradeScore];
[self.tableView reloadData];
}
#pragma mark - TABLE VIEW DATASOURCE METHODS
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
[super tableView:tableView cellForRowAtIndexPath:indexPath];
self.pugMenuEntity = [self.fetchedResultsController objectAtIndexPath:indexPath];
if (self.totalNumberOfRows < 2) {
self.cell.textLabel.text = [NSString stringWithFormat:@"%@", self.pugMenuEntity.topic];
} else {
self.cell.textLabel.text = [NSString stringWithFormat:@"%ld %@", (long)(indexPath.row + 1), self.pugMenuEntity.topic];
}
if (!self.pugMenuEntity.gradeScore) {
self.cell.detailTextLabel.text = @"";
}
else{
self.cell.detailTextLabel.text = [NSString stringWithFormat:@"%0.0f%%", self.pugMenuEntity.gradeScore];
}
return self.cell;
}
#pragma mark - NAVIGATION METHODS
- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
[super prepareForSegue:segue sender:sender];
self.pugMenuEntity = [self.fetchedResultsController objectAtIndexPath:self.selectedIndexPath];
[self.startViewController valuesFromMasterViewController:self.pugMenuEntity.topic majorSubjectName:self.pugMenuEntity.tabName image:self.pugMenuEntity.imageName introductoryText:self.pugMenuEntity.introText andTabBarItemTitle:self.tabBarItem.title];
}
@end