Skip to content

Instantly share code, notes, and snippets.

@ksm
Created July 1, 2012 21:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ksm/3029763 to your computer and use it in GitHub Desktop.
Save ksm/3029763 to your computer and use it in GitHub Desktop.
Batching up database changes into a single save
// Source: Stanford CS193P November 16, 2010 Lecture 16
// Use case: lots of Core Data changes. You want them to save once they settle down.
- (void)delayedSave:(NSManagedObjectContext *)ctxt
{
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(doSave:) object:ctxt];
[self performSelector:@selector(doSave:) withObject:ctxt afterDelay:1.0];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment