how can i use *[10] type?

Discussion in 'iOS Programming' started by junmoney83, Mar 8, 2010.

  1. junmoney83 macrumors newbie

    Mar 3, 2010
    @interface testTable2ViewController : UIViewController 
    	NSMutableArray **indexStore;
    @property(nonatomic , retain) NSMutableArray **indexStore;
    @implementation testTable2ViewController
    @synthesize indexStore;
    - (void)viewDidLoad 
    	NSMutableArray *jung[10];
    	for (NSInteger i = 0; i <10; i++)
    		jung[i] = [[NSMutableArray alloc]init];
    		indexStore[i] = [[NSMutableArray alloc]init];
    jung = [[NSMutableArray alloc]init]; is working good....
    but indexStore = [[NSMutableArray alloc]init]; can't work
    Error Message is EXC_BAD_ACCESS...

    why it is not working?
  2. chown33 macrumors 604

    Aug 9, 2009
    Because indexStore is nil.

    You define the variable in the header. Good.

    You use the contents of the variable in viewDidLoad. Bad.

    You need something that will run before viewDidLoad, which will initialize the testTable2ViewController so it's ready for use. Normally, that's an -init method of some kind.
  3. junmoney83 thread starter macrumors newbie

    Mar 3, 2010
    but this is working...

    jung = [[NSMutableArray alloc]init];
    is working good.
  4. dejo Moderator


    Staff Member

    Sep 2, 2004
    The Centennial State
    NSMutableArray [COLOR="Red"]**[/COLOR]indexStore;
    You sure you want a pointer to a pointer there?
  5. chown33 macrumors 604

    Aug 9, 2009

    Because the jung array is declared as an array. You didn't declare indexStore as an array.

    If you want an array, you have to define the variable as an array. For example, if you want indexStore to be an array of 10 NSMutable-pointers, you should use this in your .h file:
    NSMutableArray *indexStore[10];
    It seems like you don't fully understand the difference between pointer-to-pointer (indexStore, for example) and array-of-pointer (jung, for example).

    If you explain what you're trying to accomplish, then it might be easier to offer advice. All we know is that you're having trouble, but since we don't know what you're trying to do, we can't really offer any specific advice.

Share This Page