1

I'm trying to convert the below method in JAVA to Objective-C

public static Object[] appendArray(Object[] objs,String...strings) {

      Object[] result= new Object[objs.length+strings.length];

      System.arraycopy(strings, 0, result, 0, strings.length);

      System.arraycopy(objs, 0, result, strings.length, objs.length);

      return result;
   }

When I wanted to translate this to obj-c is it going to be something like this:

 +(NSArray *)appendArray:(NSArray *)objs andStringField:(NSArray *)strings{
   }

Is there an equivalent of System.arraycopy for Objective-C?

1 Answer 1

1

System.arraycopy makes a shallow copy so all it's doing is creating a new array. In your case you want to append 2 arrays together so you want to make an intermediate array that is mutable and then add the contents of both source arrays:

NSMutableArray *transient = [objs mutableCopy];
[transient addObjectsFromArray:strings];

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

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.