Reputation: 1175
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?
Upvotes: 1
Views: 459
Reputation: 119031
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;
Upvotes: 1