以下の例では、なぜセッターがmyString
のために合成されていませんか?以下の基本的な割り当ては、myString
がnil
になります。セッター[self setMyString:s];
を使用しようとすると、認識できないセレクタ例外が発生します。目的関数-cのシャドウイングに関する問題
// in .h file
@interface MyClass
@property (nonatomic, readonly) NSString *myString;
@end
// in .m file
@interface MyClass (MyCategory)
@property (nonatomic, copy) NSString *myString;
@end
@implementation MyClass
@synthensize myString;
- (void) someMethod:(NSString *) s {
myString = [s copy];
// why is myString nil here?
}
@end
編集:問題は、GDBとありました。 po myString
が印刷されたCan't print description of a NIL object.
。しかし、NSLog(@"myString: %@", myString);
が期待値を出力しました。
私はこれについて知りませんでした。それは便利になるかもしれないように見えます。あなたはそれが明示的にサポートされていると言います - それのためのドキュメントへのリンクがありますか?前もって感謝します。 –
@Will:https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/ObjectiveC/Chapters/ocProperties.html#//apple_ref/doc/uid/TP30001163-CH17-SW19 –
@WillPragnell [拡張機能](https://developer.apple.com/library/ios/#documentation/cocoa/conceptual/objectivec/chapters/occategories.html)。 *クラス拡張の一般的な用途は、公開されているものとして公開されているものを再読み込みすることです。* – Caleb