首页 > 代码库 > objective-c保护属性
objective-c保护属性
#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保护属性
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。