Reputation: 4716
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++;
}
Upvotes: 0
Views: 1941
Reputation: 2346
Change 5th line to this:
[arrayToFill insertObject:dictionary atIndex:i];
You don't have to reassign the arrayToFill
Upvotes: 1
Reputation: 9481
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 ];
}
Upvotes: 1
Reputation: 5591
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
Upvotes: 2