Objective-c (多输入参数的方法)

时间:2023-03-09 16:53:30
Objective-c (多输入参数的方法)

  一个方法可能具有多个输入参数。在头文件中,可以定义带有多个输入参数的方法:

  - (void)setIntX:(int)n andSetIntY:(int)d

  下面通过一个例子来说明它的具体用法:

  

 #import <Foundation/Foundation.h>

 @interface Test : NSObject{
int _X;
int _Y;
}
@property int _X,_Y; - (void)print;
- (void)setX:(int)x andSetY:(int)y; @end @implementation Test @synthesize _X,_Y;
- (void)print{
NSLog(@"x = %i , y = %i",_X,_Y);
}
- (void)setX:(int)x andSetY:(int)y{
_X = x;
_Y = y;
} @end int main(int argc , const char *argv[]){
@autoreleasepool {
Test *test = [Test new];
[test setX: andSetY:];
[test print];
}
     return 0;
}