0

In essence, what I want to do is to has a string I've created as the name for a variable. However with the code below I understandably get a redefinition error.

NSString *pointerName = @"myPointer";

NSArray *pointerName = [NSArray array];

Is there a way to use the string as its content rather than having the compiler think I mean that's the name of the new object I'm trying to create?

Mark Reid
  • 2,611
  • 3
  • 23
  • 45
  • 1
    Basically very hard, if not impossible. Most of the time there's a less tricky solution. What was your original problem? – Khanh Nguyen Oct 25 '13 at 11:20
  • I wanted to iterate through a series of elements in an array, a list of names, and use those names as part of a variable name. Something like firstPointer, secondPointer and so on. However there are a few different variables I want to use within the fast enumeration loop each using the array elements are part of their name which is what led me to this question. – Mark Reid Oct 25 '13 at 11:37
  • @MarkReid:Please put your fast enumeration loop code. – TamilKing Oct 25 '13 at 11:40

2 Answers2

1

Instead of store string value for pointer. You can use like this

NSMutableDictionary *dict = [[NSMutableDictionary alloc]init];
    for (int i = 0; i < [array1 count]; i++) 
    {
        [dict setObject:[NSArray array] forKey:[array1 objectAtIndex:i]];   
    }

I hope it is useful for you..

TamilKing
  • 1,643
  • 1
  • 12
  • 23
0

According to cocoa convention you cannot create the pointer of an object of the same name variable. Also the apple doc says the same thing please refer the link https://developer.apple.com/library/ios/documentation/cocoa/conceptual/ProgrammingWithObjectiveC/Conventions/Conventions.html

Hussain Shabbir
  • 14,801
  • 5
  • 40
  • 56