specifying an array by name, using a string. Objective C

Steve Maietta

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

Wain

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.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Trouble using strcpy with character array and string values in Objective-C

From Dev

using an array objective C / iOS

From Dev

Objective C substite method trigger name with string

From Dev

Using "?" in variable name for Objective-C development

From Dev

Objective-C PFQuery for string contained in an array?

From Dev

parse JSON string into array of objects Objective C

From Dev

Concatenate String in Array of Integers in Objective C

From Dev

Objective-C PFQuery for string contained in an array?

From Dev

specifying arguments to an Objective-C commandline app

From Dev

Objective-C - Using Enum identifiers as string

From Dev

Replace substring into a string using objective C

From Dev

Objective-C Array allocation using @[] and initWithObjects

From Dev

Swift / Objective C: How to get value from object by string name

From Dev

How to avoid using "and" in Objective-C method name

From Dev

Building a string and using it as the function array name

From Dev

using string value instade of array name in vba

From Dev

Sorting an array of objects specifying sort criteria as a string

From Dev

Objective-C: How to find the most common string in an array?

From Dev

Objective-C: How to find the most common string in an array?

From Dev

parse JSON string to NSDictionary into array of objects Objective C

From Dev

How to find greatest numeric value in Array of string in objective-c?

From Dev

How to add Array as string in Core Data in Objective c

From Dev

Objective c- get sub json string in json array

From Dev

Clean a string in objective c

From Dev

Objective C String Manipulation

From Dev

Make A Call In Objective-C To A Method Using Swift String

From Dev

How to parse a string to date using dateformatter in objective c

From Dev

Objective-C - Translate string to different characters using a dictionary

From Dev

Find String Path in Matrix using objective-c

Related Related

  1. 1

    Trouble using strcpy with character array and string values in Objective-C

  2. 2

    using an array objective C / iOS

  3. 3

    Objective C substite method trigger name with string

  4. 4

    Using "?" in variable name for Objective-C development

  5. 5

    Objective-C PFQuery for string contained in an array?

  6. 6

    parse JSON string into array of objects Objective C

  7. 7

    Concatenate String in Array of Integers in Objective C

  8. 8

    Objective-C PFQuery for string contained in an array?

  9. 9

    specifying arguments to an Objective-C commandline app

  10. 10

    Objective-C - Using Enum identifiers as string

  11. 11

    Replace substring into a string using objective C

  12. 12

    Objective-C Array allocation using @[] and initWithObjects

  13. 13

    Swift / Objective C: How to get value from object by string name

  14. 14

    How to avoid using "and" in Objective-C method name

  15. 15

    Building a string and using it as the function array name

  16. 16

    using string value instade of array name in vba

  17. 17

    Sorting an array of objects specifying sort criteria as a string

  18. 18

    Objective-C: How to find the most common string in an array?

  19. 19

    Objective-C: How to find the most common string in an array?

  20. 20

    parse JSON string to NSDictionary into array of objects Objective C

  21. 21

    How to find greatest numeric value in Array of string in objective-c?

  22. 22

    How to add Array as string in Core Data in Objective c

  23. 23

    Objective c- get sub json string in json array

  24. 24

    Clean a string in objective c

  25. 25

    Objective C String Manipulation

  26. 26

    Make A Call In Objective-C To A Method Using Swift String

  27. 27

    How to parse a string to date using dateformatter in objective c

  28. 28

    Objective-C - Translate string to different characters using a dictionary

  29. 29

    Find String Path in Matrix using objective-c

HotTag

Archive