Created
May 31, 2013 19:36
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (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