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 }

 

转载于:https://www.cnblogs.com/xiaozhai-1234/p/5248776.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值