To be or not to be.That is a question!

---源于莎士比亚的《哈姆雷特》

导航

类的通用格式

Test.h:

#import <Foundation/Foundation.h>
@interface Test : NSObject
{
    int intX;
    int intY;
}

-(void) print;
-(void) setIntX:(int) n;
-(void) setIntY:(int) d;

-(int) intX;
-(int) intY;
@end

Test.m:

#import "Test.h"
@implementation Test
-(void) print
{
    NSLog(@"int add result: %i",intX+intY);
}

-(void) setIntX:(int)n
{
    intX=n;
}
-(void) setIntY:(int)d
{
    intY=d;
}

-(int) intX
{
    return intX;
}
-(int) intY
{
    return intY;
}


@end

main.m:

#import <Foundation/Foundation.h>
#import "Test.h"

int main(int argc,const char *argv[])
{
    @autoreleasepool {
        Test *test=[[Test alloc] init];
        [test setIntX:1];
        [test setIntY:1];
        [test print];
    }
    return 0;
}

console 输出:

2013-09-18 14:05:21.354 Obj-c[1228:303] int add result: 2

 

posted on 2013-09-18 14:13  Ijavascript  阅读(234)  评论(0编辑  收藏  举报