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 { - (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; _activeUserOID = activeUser.objectID;
} }

View File

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

View File

@ -799,6 +799,12 @@
newElement.loginName = activeElement.loginName; newElement.loginName = activeElement.loginName;
[activeElement.managedObjectContext deleteObject:activeElement]; [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; _activeElementOID = newElement.objectID;
activeElement = newElement; activeElement = newElement;
} }
@ -813,6 +819,10 @@
- (void)didSelectElement:(MPElementEntity *)element { - (void)didSelectElement:(MPElementEntity *)element {
inf(@"Selected: %@", element.name); 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; _activeElementOID = element.objectID;
[self closeAlert]; [self closeAlert];

View File

@ -1139,6 +1139,11 @@
- (void)setSelectedUser:(MPUserEntity *)selectedUser { - (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; _selectedUserOID = selectedUser.objectID;
} }