Reputation: 1032
I am trying to write a method which allows me to create a different String permutations, based on the values I have stored within 3 different arrays. Currently I have a NSMutableDictionary
that contains 3 different keys, and associated to each key we have an NSMutableArray
array that contains a list of different String objects.
How woulld I loop through each of my NSMutableArray
arrays which are stored within my NSMutableDictionary
, and build a string value for each node from the arrays. So essentially, something like the following: A1[0] = "Hello"
, A2[0] = "There"
, A3[0] = "Guys"
, which would essentially build me a string like this: "HelloThereGuys".
Any suggestions, or possibly different approaches to this problem will be appreciated.
Upvotes: 0
Views: 72
Reputation: 16650
First of all I want to agree with hochl. ;-) But I think, that you want to create a string containing a word from each array in the same index position?
NSMutableArray *enums = [NSMutableArray new];
for( NSString *key in dictionary )
{
NSEnumerator *enum = [dictionary[key] objectEnumerator]; // Forgot that in prior version
[enums addObject:enum];
}
while( YES )
{
NSMutableString *line = [NSMutableString new];
BOOL done = NO;
for( NSEnumerator *enum in enums )
{
NString *word = [enum nextObject];
if( word == nil )
{
done = YES;
break;
}
[line addString:word];
}
if (done)
{
break;
}
NSLog (@"%@", line );
}
Did I get you right?
Upvotes: 1