如何在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屋!