0
votes

Okay. I have been trying organise this nsmutable array so my program can use it in the way I want.

I started off with a standard NSMutable array then use the addobject: method to populate it and then also populated it with more NSMutableArrays (so array in arrays). Because of this I need to call the ObjectAtIndex: method a lot and also the replaceObjectAtIndex: withObject: method alot. Also because you can only ad object with type ID to NSMutableArrays (I think at least) I've had to convert all of my double variables to NSNumbers and then back to doubles to maths with and then back to NSNumbers to store again... Hardly efficient.

But the main problem is (the previous things were just stuff I was curious about), this code:

NSMutableArray * array = [tmp objectAtIndex x];
[tmp replaceObjectAtIndex:x withObject: [array replaceObjectAtIndex:2 withObject: result]];

Xcode says the problem is on the second line, I just added the firrst for a bit on context. Result is an NSNumber and tmp is also a NSMutableArray. Xcode says the error is "Sending 'Void' to parameter of incompatible type 'id'".

I'd really appreciate any help :). Thanks!

2
It's always a good idea, when you're getting strange error messages, to break a complex expression down into individual lines. This lets you determine which specific construct is raising the error. - Hot Licks
Thanks Hot Licks. That seems to be what Jack Lawrence also said in my chosen answer :). As you probbaly guessed I'm relatively new and was doing this at 3am last night :/. I posted this and then crashed last night :). - Greg Cawthorne

2 Answers

3
votes

Lets break down the line [tmp replaceObjectAtIndex:x withObject: [array replaceObjectAtIndex:2 withObject: result]];.

When you see a problem like this and you have a bunch of nested methods, start at the deepest method call and move out, checking documentation to see what each method returns. In this case the answer is simple, but it's always good practice:

-[NSMutableArrray replaceObjectAtIndex:withObject:] returns void, therefore:

[tmp replaceObjectAtIndex:x withObject: void] , therefore passing void as the second argument in replaceObjectAtIndex:withObject: which Xcode should rightfully complain about.

1
votes

The return type for replaceObjectAtIndex is void, so that's why you get that error. Your intent was to add the array, but you're just adding the result of that whole expression, which is void. You need to have the replaceObjectAtIndex method as a separate line, and then use array as the object argument.