Permalink
Browse files

Added a separate method that takes variadic args

  • Loading branch information...
1 parent b872a58 commit d2d2876f6bbc6537ee842b06fd39fffd0fd87d01 @thestoics thestoics committed Jun 12, 2012
Showing with 17 additions and 10 deletions.
  1. +2 −1 Source/JSObjectionInjector.h
  2. +13 −8 Source/JSObjectionInjector.m
  3. +1 −0 Source/JSObjectionUtils.m
  4. +1 −1 Specs/InitializerSpecs.m
@@ -10,5 +10,6 @@
- (id)initWithContext:(NSDictionary *)theGlobalContext;
- (id)initWithContext:(NSDictionary *)theGlobalContext andModule:(JSObjectionModule *)theModule;
- (id)initWithContext:(NSDictionary *)theGlobalContext andModules:(NSArray *)modules;
-- (id)getObject:(id)classOrProtocol, ...;
+- (id)getObject:(id)classOrProtocol;
+- (id)getObjectWithArgs:(id)classOrProtocol, ... NS_REQUIRES_NIL_TERMINATION;
@end
@@ -69,23 +69,23 @@ - (id)initWithContext:(NSDictionary *)theGlobalContext andModules:(NSArray *)mod
}
-- (id)getObject:(id)classOrProtocol, ... {
+- (id)getObjectWithArgs:(id)classOrProtocol, ... {
@synchronized(self) {
if (!classOrProtocol) {
return nil;
}
-
+
NSString *key = nil;
if (class_isMetaClass(object_getClass(classOrProtocol))) {
key = NSStringFromClass(classOrProtocol);
} else {
key = [NSString stringWithFormat:@"<%@>", NSStringFromProtocol(classOrProtocol)];
}
-
-
+
+
id<JSObjectionEntry> injectorEntry = [_context objectForKey:key];
injectorEntry.injector = self;
-
+
if (!injectorEntry) {
id<JSObjectionEntry> entry = [_globalContext objectForKey:key];
if (entry) {
@@ -94,19 +94,24 @@ - (id)getObject:(id)classOrProtocol, ... {
[_context setObject:injectorEntry forKey:key];
}
}
-
+
if (classOrProtocol && injectorEntry) {
va_list va_arguments;
va_start(va_arguments, classOrProtocol);
NSArray *arguments = JSObjectionUtils.transformVariadicArgsToArray(va_arguments);
va_end(va_arguments);
return [injectorEntry extractObject:arguments];
}
-
+
return nil;
}
-
+
return nil;
+
+}
+
+- (id)getObject:(id)classOrProtocol {
+ return [self getObjectWithArgs:classOrProtocol, nil];
}
#pragma mark - Private
@@ -64,6 +64,7 @@ static JSObjectionPropertyInfo FindClassOrProtocolForProperty(objc_property_t pr
static NSArray* TransformVariadicArgsToArray(va_list va_arguments) {
NSMutableArray *arguments = [NSMutableArray array];
+
id object;
while ((object = va_arg( va_arguments, id ))) {
[arguments addObject:object];
View
@@ -17,7 +17,7 @@
});
it(@"will override the default arguments if arguments are passed to the injector", ^{
- ViewController *controller = [injector getObject:[ViewController class], @"AnotherNib", @"pretendBundle", nil];
+ ViewController *controller = [injector getObjectWithArgs:[ViewController class], @"AnotherNib", @"pretendBundle", nil];
[[controller.nibName should] equal:@"MyNib"];
[[controller.bundle should] equal:@"pretendBundle"];

0 comments on commit d2d2876

Please sign in to comment.