如何在 Objective-C 中传递多个参数? [英] How do I pass multiple parameters in Objective-C?
问题描述
我已经阅读了一些关于 Objective-C 方法语法的帖子,但我想我不明白一个方法的多个名称.
I have read several of the post about Objective-C method syntax but I guess I don't understand multiple names for a method.
我正在尝试创建一个名为 getBusStops
的方法,它带有 NSString
和 NSTimeInterval
参数,返回类型为 NSMutableArray代码>.这是我构造方法的方式,但它显然在运行时出错:
I'm trying to create a method called getBusStops
with NSString
and NSTimeInterval
parameters and a return type of NSMutableArray
. This is how I have constructed the method but it obviously gets errors at runtime:
- (NSMutableArray *)getBusStops:(NSString *)busStop
(NSTimeInterval *)timeInterval;
我看到了另一个使用方法的例子:
I saw another example with a method:
-(NSInteger)pickerView:(UIPickerView *)pickerView
numberOfRowsInComponent:(NSInteger)component
我不明白为什么这个方法的每个参数都有一个方法名称.我应该对类似的事情做同样的事情:
I don't understand why this method has a method name for each parameter. Should I do the same with something like:
- (NSMutableArray *)getBusStops:(NSString *)busStop
forTime:(NSTimeInterval *)timeInterval
推荐答案
Objective-C 没有命名参数,因此冒号左侧的所有内容都是方法名称的一部分.例如,
Objective-C doesn't have named parameters, so everything on the left side of a colon is part of the method name. For example,
getBusStops: forTime:
是方法的名称.名称已拆分,因此可以更具描述性.你可以简单地命名你的方法
is the name of the method. The name is broken up so it can be more descriptive. You could simply name your method
getBusStops: :
但这并没有告诉你太多关于第二个参数的信息.
but that doesn't tell you much about the second parameter.
这篇关于如何在 Objective-C 中传递多个参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!