0

I have a problem with a NSMutableArray. I want to create a loop that fill an mutableArray initially empty but Xcode generates two error: "Assigning to "NSMutableArray" from incompatible type 'void'", "void value not ignored as it ought to be". This is the code:

NSMutableArray * arrayToFill =[[NSMutableArray alloc]init];
int i=0;
while (i<4){
    NSDictionary * dictionary =[[NSDictionary dictionaryWithObjectsAndKeys: @"value1", @"key1",@"value2",@"key2", nil];
    arrayToFill =[arrayToFill insertObject:dictionary atIndex:i];
    i++;
 }

3 Answers 3

2

Change the line:

arrayToFill =[arrayToFill insertObject:dictionary atIndex:i];

to

[arrayToFill insertObject:dictionary atIndex:i];

You don't need to assign it again, just call the insert method

Sign up to request clarification or add additional context in comments.

Comments

1

simply remove the arrayToFill =

 NSMutableArray * arrayToFill = [NSMutableArray array];
    for (int i = 0; i < 4; i++){
        NSDictionary * dictionary = [NSDictionary dictionaryWithObjectsAndKeys: @"value1",  @"key1", @"value2", @"key2", nil];
        [arrayToFill insertObject: dictionary atIndex: i ];
     }

Comments

1

Change 5th line to this:

[arrayToFill insertObject:dictionary atIndex:i];

You don't have to reassign the arrayToFill

Comments

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.