【发布时间】:2013-09-24 11:02:19
【问题描述】:
我看到了这个 thread,但在 iOS7 中并不完全清楚,因为编程指南说您可以省略属性的 @synthesise 关键字。
我想要一个@property,外部是readonly,内部是readwrite。我可以像这样只使用@property 关键字吗?
编辑:在所提供的答案中,哪些被认为更正确,或者至少更惯用。要在 Class 扩展中拥有单独的 readwrite 属性或直接在实现中访问 ivar?
编辑:按照答案中的建议,表明我正在使用类扩展。
//.h
@interface CACustomerAuthenticator : NSObject
@property (nonatomic, copy, readonly) NSString *username;
@end
//.m
@interface CACustomerAuthenticator ()
@property (nonatomic, copy, readwrite) NSString *username;
@end
【问题讨论】:
标签: ios objective-c properties encapsulation