I am trying to use a loop to print out the contents of 26 arrays, rather than printing out each in turn.
The problem I am having is in the NSLog below where I call the specific array. I am trying to use the "stringName" string to specify which array I want to count.
….list of arrays starting at beginWithA….
NSArray *beginWithT = [randomList filteredArrayUsingPredicate:tPredicate];
NSArray *beginWithU = [randomList filteredArrayUsingPredicate:uPredicate];
NSArray *beginWithV = [randomList filteredArrayUsingPredicate:vPredicate];
NSArray *beginWithW = [randomList filteredArrayUsingPredicate:wPredicate];
NSArray *beginWithX = [randomList filteredArrayUsingPredicate:xPredicate];
NSArray *beginWithY = [randomList filteredArrayUsingPredicate:yPredicate];
NSArray *beginWithZ = [randomList filteredArrayUsingPredicate:zPredicate];
NSString *alphabet = @"ABCDEFGHIJKLMNOPQRSTUVWXYZ";
for (int i =0; i<26; i++)
{
unichar c = [alphabet characterAtIndex:i];
NSString *stringName = [NSString stringWithFormat:@"beginWith%C", ch];
NSLog (@"The %C Array contains %lu words.", [stringName count]);
}
I know that just dropping the string name into the spot thats looking for an array won't work but for the sake of clarity here this seemed best. Ive tried many variations and options.
I understand that this may not be a good way to go, but I'm so close! Any help would be greatly appreciated.
thanks ~Steve
You should really change your approach. Rather than having 26 different properties for the arrays you should have an array of arrays, or a dictionary where the keys is the 'letter's and the values are the associated arrays (the choice depends on what you're using them for).
If you update your data model to this it should be easier to use in your existing code and your current problem becomes trivial (logging the container will log the contents).
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments