Should the following while statement not exit after a maximum of one execution?
while ( [self.managedObjectContext hasChanges] )
[self.managedObjectContext processPendingChanges];
hasChanges
remains true while the context has changes that have not been flushed to disk. What you're looking for is save:
, which will call through to processPendingChanges
in addition to writing changes in the context to disk and altering the changed state of the context.