点语法应用

//.语法 又称链式结构 只有在属性拥有get set方法的时候才会有用。它会根据具体的书写情况进行调用get/set方法

@interface People : NSObject

{

    int agewith;

}

 

//setter方法必须遵守驼峰法

//getter方法必须遵守驼峰法

- (void)setAgeWith:(int)newAge;

- (int)ageWith;

 

- (void)display;

@end

 

#import "People.h"

 

@implementation People

 

- (void)setAgeWith:(int)newAge

{

    agewith = newAge;

}

 

- (int)ageWith

{

    return agewith;

}

 

- (void)display

{

 

 

}

 

@end

 

#import <Foundation/Foundation.h>

#import "People.h"

 

int main(int argc, const char * argv[]) {

 

    @autoreleasepool {

        People *peo = [[People alloc]init];

        peo.ageWith = 10;           //内部自动调用set方法 等于 [peo setAgeWith:10];

        NSLog(@"%d",peo.ageWith);   //内部自动调用get方法 等于[peo ageWith];

    }

    return 0;

 

}

posted on 2016-04-16 13:56  小|晄  阅读(65)  评论(0编辑  收藏  举报

导航