首页 > 其他 > 详细

objective-c保护属性

时间:2014-10-15 10:18:11      阅读:289      评论:0      收藏:0      [点我收藏+]
#import <Foundation/Foundation.h>

@interface ClassVirable : NSObject{
    NSInteger year;//保护树形
}
@property int age;//不用在实现文件中写@synthesize age就会有setAge:和age方法了
-(void)set:(NSInteger)i;
@end
#import "ClassVirable.h"

@implementation ClassVirable
///Property implementation must have its declaration in interface ‘ClassVirable‘
//@synthesize year;
-(void)set:(NSInteger)i{
    self.age = i;
    year = i;
}
@end
#import <Foundation/Foundation.h>
#import "ClassVirable.h"
int main(int argc, const char * argv[])
{

    @autoreleasepool {
        ClassVirable *c = [[ClassVirable alloc]init];
        [c set:2];
        [c setAge:20];
        NSLog(@"%i",[c age]);
        NSLog(@"%i",c.age);
        //Instance variable ‘year‘ is protected
//        NSLog(@"%ld",(long)c->year);
    }
    return 0;
}

 

objective-c保护属性

原文:http://www.cnblogs.com/ghgyj/p/4025659.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!