Add another shared object factory method flavor.

This commit is contained in:
Jeff Arena
2013-04-02 11:58:54 -04:00
parent f8d65d5a6f
commit 6c842b4fdb
2 changed files with 12 additions and 0 deletions

View File

@@ -144,6 +144,7 @@ extern NSString * const RKTestFactoryDefaultNamesManagedObjectStore;
@return The shared object instance for the factory registered with the given name.
*/
+ (id)sharedObjectFromFactory:(NSString *)factoryName;
+ (id)sharedObjectFromFactory:(NSString *)factoryName properties:(NSDictionary *)properties;
/**
Inserts a new managed object for the `NSEntityDescription` with the given name into the specified managed object context and sets properties on the instance from the given dictionary. A permanent managed object ID is obtained for the object so that it can be referenced across threads without any further work.

View File

@@ -94,12 +94,18 @@
}
- (id)sharedObjectFromFactory:(NSString *)factoryName
{
return [self sharedObjectFromFactory:factoryName properties:nil];
}
- (id)sharedObjectFromFactory:(NSString *)factoryName properties:(NSDictionary *)properties
{
id sharedObject = [self.sharedObjectsByFactoryName objectForKey:factoryName];
if (! sharedObject) {
sharedObject = [self objectFromFactory:factoryName properties:nil];
[self.sharedObjectsByFactoryName setObject:sharedObject forKey:factoryName];
}
[sharedObject setValuesForKeysWithDictionary:properties];
return sharedObject;
}
@@ -171,6 +177,11 @@
return [[RKTestFactory sharedFactory] sharedObjectFromFactory:factoryName];
}
+ (id)sharedObjectFromFactory:(NSString *)factoryName properties:(NSDictionary *)properties
{
return [[RKTestFactory sharedFactory] sharedObjectFromFactory:factoryName properties:properties];
}
+ (id)insertManagedObjectForEntityForName:(NSString *)entityName
inManagedObjectContext:(NSManagedObjectContext *)managedObjectContext
withProperties:(NSDictionary *)properties