0

Is there any way to do addObjectFromArray:atIndex:?

I have 2 NSMutableArrays. Lets say 1st array is array1 and the 2nd is array2. They ar filled with values. And I need to add item from array1 at index 3 to array2. Is it possible?

1
  • Does the index in array2 matter? Meaning: Do you want to have the object in array2 at the same index as in array1 (if possible)? Commented Jul 10, 2012 at 9:05

3 Answers 3

5

Retrieve the object using:

[array1 objectAtIndex:3]

Add the object using:

[array2 addObject:theObject];

In other words, the following adds object 3 from array1 to array2:

 [array2 addObject:[array1 objectAtIndex:3]];
Sign up to request clarification or add additional context in comments.

Comments

1

You need to break this into two steps, like this:

[array2 addObject: [array1 objectAtIndex: index3]];

Comments

1

We have addObjectsFromArray: method it means,adds the objects contained in another given array to the end of the receiving array’s content. But we don't have addObjectFromArray:atIndex: method. For getting your results, you can use methods what NSMutableArray class contains.

[array2 addObject: [array1 objectAtIndex: index3]];

Here we can use two methods addObject: and objectAtIndex:. For more details, use this link.

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.