简体   繁体   English

在Obj-C中等效于Java中传递对象类型的参数

[英]Passing parameters of the object type in Java equivalent in Obj-C

I'm trying to convert the below method in JAVA to Objective-C 我正在尝试将JAVA中的以下方法转换为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: 当我想将其转换为obj-c时,它将是这样的:

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

Is there an equivalent of System.arraycopy for Objective-C? 是否存在与Objective-C等效的System.arraycopy?

System.arraycopy makes a shallow copy so all it's doing is creating a new array. System.arraycopy创建一个浅表副本,因此它所要做的就是创建一个新数组。 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: 在您的情况下,您希望将2个数组附加在一起,因此您想要使中间数组可变,然后添加两个源数组的内容:

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

return transient;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM