Commits

Peter Hosey committed dc6d1af

Implemented support for passing an array to the varargs construction method, and changed the test program to demonstrate and test this.

  • Participants
  • Parent commits 35cd701

Comments (0)

Files changed (2)

 
 		id arg = nil;
 		while ((arg = va_arg(argl, id))) {
-			[array addObject:arg];
+			if ([arg isKindOfClass:[NSString class]]) {
+				[array addObject:arg];
+			} else if ([arg isKindOfClass:[NSArray class]]) {
+				for (id subarg in arg) {
+					NSAssert([subarg isKindOfClass:[NSString class]], @"Array of args %@ passed that contains a non-string (%@)", arg, subarg);
+				}
+
+				[array addObjectsFromArray:arg];
+			} else {
+				NSAssert([arg isKindOfClass:[NSString class]] || [arg isKindOfClass:[NSArray class]], @"Only strings and arrays of strings are valid arguments");
+			}
 		}
 	}
 

PRHTaskTest/PRHTaskTest/main.m

 int main (int argc, char **argv) {
 	NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
 
-	PRHTask *task = [PRHTask taskWithProgramName:@"echo" arguments:@"I am the very model of a modern Major-General", nil];
+	//When using the varargs method, strings and arrays of strings can be mixed in the arguments parameter list.
+	PRHTask *task = [PRHTask taskWithProgramName:@"echo" arguments:@"I am the very model of a", [NSArray arrayWithObjects:@"modern", @"Major-General", nil], nil];
 	task.accumulatesStandardOutput = YES;
 
 	task.successfulTerminationBlock = ^(PRHTask *completedTask) {