0

I have declared a NSMutable Array with 50 size. As i want to use each index as an array and add data separately. e.g i want to add 10 object to first Index 5 to next and so on. Is this the right way to do it? Please help me out if there is an alternate way.The sdk gives me error at line 5 saying 'Cannot convert to a pointer type'.

NSMutableArray *myArray[50];    
@property (nonatomic, retain) NSMutableArray *myArray;            
@dynamic myArray; 
for (int i = 0; i < count; i++)     
{                                   
    myArray[i] = [NSMutableArray alloc];         
}

PresentationSlides[i] addObject:string];

My problem is how can i reach to a specific index.if i use this.

for (int i = 0; i < count; i++)     
{                                   
myArray = [NSMutableArray array];    
}         
[myArray objectAtIndex:i ??????   

What else? I am stuck in the projet after completing 90% of it. And there is no use of it if i couldnt complete it.

3
  • 4
    I think you are confusing C arrays for Objective-C NSArrays. Commented Dec 6, 2010 at 21:51
  • @BoltClock i am sure you have understand what i am trying to do. So can u suggest me a better way. Any optimized solution Commented Dec 6, 2010 at 21:58
  • @T. A.: Are you trying to have a C array of 50 NSMutableArrays or an NSMutableArray of 50 objects or what? Commented Dec 6, 2010 at 22:00

1 Answer 1

2

You'll have to allocate myArray:

myArray = [NSMutableArray arrayWithCapacity:50];

Then for line 5, in the loop, 'alloc' alone isn't enough. Try:

[myArray insertObject:[[NSMutableArray alloc] initWithCapacity:10] atIndex:i];
Sign up to request clarification or add additional context in comments.

2 Comments

Thats terrific , Now can u tell me , how to access ) 0th index of myArray. As the 0th index is itself an array so how can i then traverse in that 0th index. while(1) { [myArray objectAtindex:i++]; } This code will move the index of myArray i want to move at the indexes of 0th array which are 10.
[[myArray objectAtIndex: 0] objectAtIndex: 42];

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.