0

I like to copy the array A elements to Array B elements with specific

example :

array A=[0123]        
array  b=[1111111111111111111]

i want `b=[1111111101231111111]

int ip=0;                        
[b addObjectsFromArray:[A objectsAtIndexes:[NSIndexSetindexSetWithIndexesInRange:NSMakeRange(ip, 10)]]];

i know how to copy the array element , i want to know how to replace the object start from 9 to 13 in array b to replaced by array a element , can any give me hint

1
  • Why do you use the iPhone tag? Commented Mar 7, 2013 at 14:58

2 Answers 2

3
    NSArray *a = @[@0,@1,@2,@3];
    NSArray *b = @[@1,@1,@1,@1,@1,@1,@1,@1,@1,@1,@1,@1,@1,@1,@1,@1,@1,@1,@1];

    NSMutableArray *c = [b mutableCopy];
    // The range here is index->8 (9th object) and length->4
    [c replaceObjectsInRange:NSMakeRange(8,4) withObjectsFromArray:a];
Sign up to request clarification or add additional context in comments.

Comments

0

You need to create mutable copy of your array and modify them:

NSMutableArray* mutableArray = [yourArray mutableCopy];

Then you will access to this methods: https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSMutableArray_Class/Reference/Reference.html

1 Comment

hi i am using nsmutable array only. i can copy the array A but i want to replace that into array b between 9 to 13

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.