私は読み取り専用にそれを使用することなく、クラス内の、それは書き込み可能な持っている財産を望んでいた場合、私は何ができる:Objective-CのARC読み取り専用プロパティと前ARCにプライベートセッター実装
// Public declaration
@interface SomeClass : NSObject
@property (nonatomic, retain, readonly) NSString *myProperty;
@end
// private interface declaration
@interface SomeClass()
- (void)setMyProperty:(NSString *)newValue;
@end
@implementation SomeClass
- (void)setMyProperty:(NSString *)newValue
{
if (myProperty != newValue) {
[myProperty release];
myProperty = [newValue retain];
}
}
- (void)doSomethingPrivate
{
[self setMyProperty:@"some value that only this class can set"];
}
@end
ARCでは、 setMyPropertyをオーバーライドしたい場合は、retain/releaseキーワードをもう使用できないため、適切で正しいですか?
// interface declaration:
@property (nonatomic, strong, readonly) NSString *myProperty;
// Setter override
- (void)setMyProperty:(NSString *)newValue
{
if (myProperty != newValue) {
myProperty = newValue;
}
}
おかげでジョシュアを - 非常に便利!私は1つの最終的なことを困惑させてきた。 ARCのプロパティの変更については、こちらをご覧ください(http://tools.ietf.org/html/draft-pantos-http-live-streaming-08)。デフォルトでは、これらは**で合成されています**強い** ** **の割り当てよりむしろ。この場合、公開APIをよりきれいにするために、公開インタフェースのユーザーが気にする必要がないため、内部的にはプロパティが強く?うまくいけば私はここで理にかなっている。 :) –
これはオブジェクト型に対してのみ強く、より明示的にするためには 'strong'、' weak'、 'assign'を入れたいと思っています。 –
確かにオブジェクトの種類にのみ適用されますが、パブリックAPI(ヘッダファイル)でこの詳細を公開する必要があるかどうかは疑問です。それは私が照会していた本当のポイントです! –