Added inContext helper to get a managed object in another context

This commit is contained in:
Saul Mora
2011-04-19 17:41:08 -06:00
parent 89d2e38370
commit 0c60bcd4b8
6 changed files with 13 additions and 5 deletions

View File

@@ -19,7 +19,7 @@
[NSManagedObjectContext setDefaultContext:nil];
[NSManagedObjectModel setDefaultManagedObjectModel:nil];
[NSPersistentStoreCoordinator setDefaultStoreCoordinator:nil];
[NSPersistentStore setDetaultPersistentStore:nil];
[NSPersistentStore setDefaultPersistentStore:nil];
}
+ (void) handleErrors:(NSError *)error

View File

@@ -90,6 +90,8 @@
+ (NSArray *)findByAttribute:(NSString *)attribute withValue:(id)searchValue andOrderBy:(NSString *)sortTerm ascending:(BOOL)ascending;
+ (NSArray *)findByAttribute:(NSString *)attribute withValue:(id)searchValue andOrderBy:(NSString *)sortTerm ascending:(BOOL)ascending inContext:(NSManagedObjectContext *)context;
- (id) inContext:(NSManagedObjectContext *)otherContext;
#if TARGET_OS_IPHONE
+ (NSFetchedResultsController *) fetchAllSortedBy:(NSString *)sortTerm ascending:(BOOL)ascending withPredicate:(NSPredicate *)searchTerm groupBy:(NSString *)groupingKeyPath;

View File

@@ -644,6 +644,12 @@ static NSUInteger defaultBatchSize = kActiveRecordDefaultBatchSize;
return YES;
}
- (id) inContext:(NSManagedObjectContext *)otherContext;
{
NSManagedObjectID *objectID = [self objectID];
return [otherContext objectWithID:objectID];
}
- (NSNumber *)maxValueFor:(NSString *)property
{
NSManagedObject *obj = [[self class] findFirstByAttribute:property

View File

@@ -14,7 +14,7 @@
+ (NSURL *) defaultLocalStoreUrl;
+ (NSPersistentStore *) defaultPersistentStore;
+ (void) setDetaultPersistentStore:(NSPersistentStore *) store;
+ (void) setDefaultPersistentStore:(NSPersistentStore *) store;
+ (NSURL *) urlForStoreName:(NSString *)storeFileName;

View File

@@ -16,7 +16,7 @@ static NSPersistentStore *defaultPersistentStore = nil;
return defaultPersistentStore;
}
+ (void) setDetaultPersistentStore:(NSPersistentStore *) store
+ (void) setDefaultPersistentStore:(NSPersistentStore *) store
{
[defaultPersistentStore release];
defaultPersistentStore = [store retain];

View File

@@ -44,7 +44,7 @@ static NSPersistentStoreCoordinator *defaultCoordinator = nil;
{
[ActiveRecordHelpers handleErrors:error];
}
[NSPersistentStore setDetaultPersistentStore:store];
[NSPersistentStore setDefaultPersistentStore:store];
}
+ (NSPersistentStoreCoordinator *) coordinatorWithPersitentStore:(NSPersistentStore *)persistentStore;
@@ -102,7 +102,7 @@ static NSPersistentStoreCoordinator *defaultCoordinator = nil;
NSManagedObjectModel *model = [NSManagedObjectModel defaultManagedObjectModel];
NSPersistentStoreCoordinator *psc = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:model];
[NSPersistentStore setDetaultPersistentStore:[psc addInMemoryStore]];
[NSPersistentStore setDefaultPersistentStore:[psc addInMemoryStore]];
return [psc autorelease];
}