码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2016-03-06 23:32:50      阅读:158      评论:0      收藏:0      [点我收藏+]

标签:

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

  - (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 }

 

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

标签:

原文地址:http://www.cnblogs.com/xiaozhai-1234/p/5248776.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!