私は、Objective-C ランタイムをもう少しよく理解しようとしています。NSAttributedString.h
最小限のインターフェイスの後に、より広範なカテゴリが続くものを検討してくださいNSExtendedAttributedString
。
ここで、次のコードを検討してください。
NSAttributedString *attributedString = [[NSAttributedString alloc] initWithAttributedString:[[NSAttributedString alloc] initWithString:@"ABC"]];
NSLog(@"Result: %@", attributedString);
NSLog(@"Exists? %@", [NSString stringWithUTF8String:sel_getName(method_getName(class_getInstanceMethod(NSAttributedString.class, @selector(initWithAttributedString:))))]);
NSLog(@"Exists? %@", [NSString stringWithUTF8String:sel_getName(method_getName(class_getInstanceMethod(NSAttributedString.class, @selector(string))))]);
// Produces this output
2013-04-19 10:17:35.364 TestApp[53300:c07] Result: ABC{
}
2013-04-19 10:17:35.364 TestApp[53300:c07] Exists? <null selector>
2013-04-19 10:17:35.365 TestApp[53300:c07] Exists? string
標準インターフェースの一部であるインスタンス メソッドが見つかりますが、カテゴリのインスタンス メソッドは見つかりません。これがどのように発生し、正常に呼び出されるのでしょうか? 内省してカテゴリメソッドを見つける方法はありますか?