2015年6月18日星期四

[笔记] Objective-c 奇奇怪怪的地方

If you need to supply multiple parameters, the syntax is again quite different from C. Multiple parameters to a C function are specified inside the parentheses, separated by commas; in Objective-C, the declaration for a method taking two parameters looks like this:

- (void)someMethodWithFirstValue:(SomeType)value1 secondValue:(AnotherType)value2;

In this example, value1 and value2 are the names used in the implementation to access the values supplied when the method is called, as if they were variables.

(reference: http://stackoverflow.com/questions/722651/how-do-i-pass-multiple-parameters-in-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,

- (NSMutableArray *)getBusStops:(NSString *)busStop
                        forTime:(NSTimeInterval *)timeInterval

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.

My question: Then, how can I call a method?

没有评论:

发表评论