美文网首页
@synthesize和@dynatmic

@synthesize和@dynatmic

作者: 起个名字真难啊2015 | 来源:发表于2017-03-24 12:56 被阅读36次
@interface Test : NSObject

@property (nonatomic, strong) NSString * name;

@property (nonatomic, assign) NSInteger age;

@property (nonatomic, strong) NSString * sex;

@end
@interface Test(){
    NSString *_chance;
}

@end

@implementation Test

//自动实现setter和getter
//@synthesize name;

//系统默认是这样滴
//@synthesize name = _name;

//但事实你可以这样写
@synthesize name = _chance;

//用户自己实现sex的setter和getter方法
@dynamic sex;

@end
#import "SubTest.h"

@implementation SubTest

//重载父类的属性
@synthesize sex = _sex;

@end

相关文章

网友评论

      本文标题:@synthesize和@dynatmic

      本文链接:https://www.haomeiwen.com/subject/ejxfottx.html