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

objective-c保护属性

时间:2014-10-15 12:00:20      阅读:147      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   io   ar   文件   sp   div   on   

#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保护属性

标签:style   blog   color   io   ar   文件   sp   div   on   

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

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