Skip to content

Instantly share code, notes, and snippets.

@chriseidhof
Created May 31, 2013 19:36
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chriseidhof/5687433 to your computer and use it in GitHub Desktop.
Save chriseidhof/5687433 to your computer and use it in GitHub Desktop.
A method that you can use in your test cases so you'll have a managed object context around.
- (NSManagedObjectContext*)managedObjectContextForTesting {
NSURL *modelURL = [[NSBundle mainBundle] URLForResource:@"YourModelName" withExtension:@"momd"];
NSManagedObjectModel* model = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL];
NSPersistentStoreCoordinator* coordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:model];
[coordinator addPersistentStoreWithType:NSInMemoryStoreType configuration:nil URL:nil options:nil error:NULL];
NSManagedObjectContext* managedObjectContext= [[NSManagedObjectContext alloc] init];
managedObjectContext.persistentStoreCoordinator = coordinator;
return managedObjectContext;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment