您的位置:首页 > 移动开发 > Objective-C

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

2016-03-06 22:20 399 查看
  一个方法可能具有多个输入参数。在头文件中,可以定义带有多个输入参数的方法:

  - (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:10 andSetY:10];
[test print];
}
     return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: