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

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

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

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

  

 1 #import <Foundation/Foundation.h>
 2 
 3 @interface Test : NSObject{
 4     int _X;
 5     int _Y;
 6 }
 7 @property int _X,_Y;
 8 
 9 - (void)print;
10 - (void)setX:(int)x andSetY:(int)y;
11 
12 @end
13 
14 @implementation Test
15 
16 @synthesize _X,_Y;
17 - (void)print{
18     NSLog(@"x = %i , y = %i",_X,_Y);
19 }
20 - (void)setX:(int)x andSetY:(int)y{
21     _X = x;
22     _Y = y;
23 }
24 
25 @end
26 
27 int main(int argc , const char *argv[]){
28     @autoreleasepool {
29         Test *test = [Test new];
30         [test setX:10 andSetY:10];
31         [test print];
32     }
     return 0;
33 }

 

posted @ 2016-03-06 22:20  雨雪先行  阅读(365)  评论(0编辑  收藏  举报