我对ARC比较新。我正在创建一个UIView
子类,它将有两个标签(标题和副标题)。我不想公开将标签公开为属性,只公开它们的文本。
我目前正在使用它:
@interface MyView : UIView
@property (nonatomic, strong) NSString *title;
@property (nonatomic, strong) NSString *subtitle;
@end
@implementation MyView
{
UILabel *_titleLabel;
UILabel *_subtitleLabel;
}
- (void)setTitle:(NSString *)title
{
[_titleLabel setText:title];
}
- (NSString *)title
{
return [_titleLabel text];
}
- (void)setSubtitle:(NSString *)subtitle
{
[_subtitleLabel setText:title];
}
- (NSString *)subtitle
{
return [_subtitleLabel text];
}
@end
我的两个@properties是否正确声明了?我应该使用strong
,weak
还是其他任何限定符?为什么?
答案 0 :(得分:1)
如果你打算使用setter / getter,我认为合适的标签是readwrite
。当属性是实例变量的setter / getter时,strong
weak
retain
等适用。