方法参数中的指针 - Objective-C
如何在方法中将指针作为参数传递? 例如:
-(void) dosomething:(NSString *) simpleString :(NSMutableArray *) pointerToArray;
其中 simpleString 是简单参数,pointerToArray 是指向数组的指针;
How to pass pointer as param in method?
for example:
-(void) dosomething:(NSString *) simpleString :(NSMutableArray *) pointerToArray;
where simpleString is simple param, and pointerToArray is pointer to an array;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在 Objective-C 中,字符串和数组都是类。正如您所看到的,它们已经可以通过指针访问。因此,您只需按照声明所示使用它们即可:
并且您可以像这样调用:
FWIW,您的方法的名称是
dosomething::
。通常会表示每个参数,所以我会这样称呼它:那么名称是
doSomethingWithString:array:
,在我看来,它更具可读性。你调用它:
In Objective-C, strings and arrays are both classes. As you can see, they are already accessed through pointers. So you simply use them as the declaration says:
And you invoke like:
FWIW, the name of your method is
dosomething::
. It is customary to denote each parameter, so I would call it:then the name is
doSomethingWithString:array:
which is much more readable, IMO. Youinvoke it with:
像这样:(
将第二个“*”添加到参数类型中
,然后在您的方法中执行以下操作:
Like this:
(Add a second '*' to the parameter type
In your method, you then do something like:
例如:
For example: