我看到这个thread,但在编程指南中指出,您可以忽略@synthesise
关键字的属性,但在iOS7中并不完全清楚。readonly public,readwrite私有财产
我想有一个@property
即readonly
外部,但readwrite
内部。我可以只使用这样的@property
关键字吗?
编辑:什么会被认为是更正确的,或至少更多地道的提供的答案。在类扩展中使用单独的readwrite
属性还是直接在实现中访问伊娃?
编辑:显示我正在使用类扩展,如答案中所建议。
//.h
@interface CACustomerAuthenticator : NSObject
@property (nonatomic, copy, readonly) NSString *username;
@end
//.m
@interface CACustomerAuthenticator()
@property (nonatomic, copy, readwrite) NSString *username;
@end
你是说我在我的类扩展中不需要任何东西,只有界面中的只读属性? – retrodev
然后,我需要直接在我的实现中访问_username,而不是通过访问者? – retrodev
是的,但您必须通过ivar _username – pNre