2
0

Don't use temporary objectIDs for state.

[FIXED]     Make sure we have permanent ObjectIDs before storing them in state.
[FIXED]     MP-14
This commit is contained in:
Maarten Billemont 2013-04-30 00:32:30 -04:00
parent c73f89e4a1
commit 0ee1e176ed
5 changed files with 59 additions and 44 deletions

2
External/Pearl vendored

@ -1 +1 @@
Subproject commit 1a1ab801f1dbfe7266f1db6ad4359e85ed3c0eb4
Subproject commit b889e6312d5ecd9d2e45eb1402cadc6e27ed84c4

View File

@ -44,6 +44,10 @@
- (void)setActiveUser:(MPUserEntity *)activeUser {
NSError *error;
if (activeUser.objectID.isTemporaryID && ![activeUser.managedObjectContext obtainPermanentIDsForObjects:@[ activeUser ] error:&error])
err(@"Failed to obtain a permanent object ID after setting active user: %@", error);
_activeUserOID = activeUser.objectID;
}

View File

@ -145,9 +145,9 @@
NSError *error;
self.fetchedResultsControllerByLastUsed.fetchRequest.predicate = predicate;
self.fetchedResultsControllerByUses.fetchRequest.predicate = predicate;
if (![self.fetchedResultsControllerByLastUsed performFetch:&error])
if (self.fetchedResultsControllerByLastUsed && ![self.fetchedResultsControllerByLastUsed performFetch:&error])
err(@"Couldn't fetch elements: %@", error);
if (![self.fetchedResultsControllerByUses performFetch:&error])
if (self.fetchedResultsControllerByUses && ![self.fetchedResultsControllerByUses performFetch:&error])
err(@"Couldn't fetch elements: %@", error);
[self.tableView reloadData];
@ -157,50 +157,46 @@
}
// See MP-14, also crashes easily on internal assertions etc..
- (void)controllerWillChangeContent:(NSFetchedResultsController *)controller {
dbg(@"%@", NSStringFromSelector( _cmd ));
[self.tableView beginUpdates];
}
- (void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject
atIndexPath:(NSIndexPath *)indexPath forChangeType:(NSFetchedResultsChangeType)type newIndexPath:(NSIndexPath *)newIndexPath {
switch (type) {
case NSFetchedResultsChangeInsert:
dbg(@"%@ -- NSFetchedResultsChangeInsert:%@", NSStringFromSelector( _cmd ), anObject);
[self.tableView insertRowsAtIndexPaths:@[ [self tableIndexPathForFetchController:controller indexPath:newIndexPath] ]
withRowAnimation:UITableViewRowAnimationAutomatic];
break;
case NSFetchedResultsChangeDelete:
dbg(@"%@ -- NSFetchedResultsChangeDelete:%@", NSStringFromSelector( _cmd ), anObject);
[self.tableView deleteRowsAtIndexPaths:@[ [self tableIndexPathForFetchController:controller indexPath:indexPath] ]
withRowAnimation:UITableViewRowAnimationAutomatic];
break;
case NSFetchedResultsChangeUpdate:
dbg(@"%@ -- NSFetchedResultsChangeUpdate:%@", NSStringFromSelector( _cmd ), anObject);
[self.tableView reloadRowsAtIndexPaths:@[ [self tableIndexPathForFetchController:controller indexPath:indexPath] ]
withRowAnimation:UITableViewRowAnimationAutomatic];
break;
case NSFetchedResultsChangeMove:
dbg(@"%@ -- NSFetchedResultsChangeMove:%@", NSStringFromSelector( _cmd ), anObject);
[self.tableView deleteRowsAtIndexPaths:@[ [self tableIndexPathForFetchController:controller indexPath:indexPath] ]
withRowAnimation:UITableViewRowAnimationAutomatic];
[self.tableView insertRowsAtIndexPaths:@[ [self tableIndexPathForFetchController:controller indexPath:newIndexPath] ]
withRowAnimation:UITableViewRowAnimationAutomatic];
break;
}
}
//- (void)controllerWillChangeContent:(NSFetchedResultsController *)controller {
//
// [self.tableView beginUpdates];
//}
//
//- (void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject
// atIndexPath:(NSIndexPath *)indexPath forChangeType:(NSFetchedResultsChangeType)type newIndexPath:(NSIndexPath *)newIndexPath {
//
// switch (type) {
//
// case NSFetchedResultsChangeInsert:
// [self.tableView insertRowsAtIndexPaths:@[ [self tableIndexPathForFetchController:controller indexPath:newIndexPath] ]
// withRowAnimation:UITableViewRowAnimationAutomatic];
// break;
//
// case NSFetchedResultsChangeDelete:
// [self.tableView deleteRowsAtIndexPaths:@[ [self tableIndexPathForFetchController:controller indexPath:indexPath] ]
// withRowAnimation:UITableViewRowAnimationAutomatic];
// break;
//
// case NSFetchedResultsChangeUpdate:
// [self.tableView reloadRowsAtIndexPaths:@[ [self tableIndexPathForFetchController:controller indexPath:indexPath] ]
// withRowAnimation:UITableViewRowAnimationAutomatic];
// break;
//
// case NSFetchedResultsChangeMove:
// [self.tableView deleteRowsAtIndexPaths:@[ [self tableIndexPathForFetchController:controller indexPath:indexPath] ]
// withRowAnimation:UITableViewRowAnimationAutomatic];
// [self.tableView insertRowsAtIndexPaths:@[ [self tableIndexPathForFetchController:controller indexPath:newIndexPath] ]
// withRowAnimation:UITableViewRowAnimationAutomatic];
// break;
// }
//}
- (void)controllerDidChangeContent:(NSFetchedResultsController *)controller {
dbg(@"%@ on %@", NSStringFromSelector( _cmd ), [NSThread currentThread].name);
[self customTableViewUpdates];
[self.tableView endUpdates];
// [self customTableViewUpdates];
// [self.tableView endUpdates];
[self.tableView reloadData];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {

View File

@ -799,6 +799,12 @@
newElement.loginName = activeElement.loginName;
[activeElement.managedObjectContext deleteObject:activeElement];
NSError *error;
if (![newElement.managedObjectContext obtainPermanentIDsForObjects:@[ newElement ]
error:&error])
err(@"Failed to obtain a permanent object ID after changing object type: %@", error);
_activeElementOID = newElement.objectID;
activeElement = newElement;
}
@ -813,6 +819,10 @@
- (void)didSelectElement:(MPElementEntity *)element {
inf(@"Selected: %@", element.name);
NSError *error = nil;
if (element.objectID.isTemporaryID && ![element.managedObjectContext obtainPermanentIDsForObjects:@[ element ] error:&error])
err(@"Failed to obtain a permanent object ID after setting active element: %@", error);
_activeElementOID = element.objectID;
[self closeAlert];

View File

@ -1139,6 +1139,11 @@
- (void)setSelectedUser:(MPUserEntity *)selectedUser {
NSError *error = nil;
if (selectedUser.objectID.isTemporaryID &&
![selectedUser.managedObjectContext obtainPermanentIDsForObjects:@[ selectedUser ] error:&error])
err(@"Failed to obtain a permanent object ID after setting selected user: %@", error);
_selectedUserOID = selectedUser.objectID;
}