美文网首页
属性的setter、getter方法

属性的setter、getter方法

作者: 冉俊 | 来源:发表于2018-08-30 14:26 被阅读28次
// 申明属性
@property (nonatomic, copy) NSString *contentText;
// setter方法
- (void)setContentText:(NSString *)contentText {
    _contentText = contentText;
}
// getter方法
- (NSString *)contentText {
    return _contentText;
}

同时写settergetter方法时,需要在 @implementation 中写
@synthesize contentText = _contentText;

相关文章

网友评论

      本文标题:属性的setter、getter方法

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