3

@dynamic キーワードを使用して宣言されたプロパティもサポートするディクショナリの動的実装に取り​​組んでいます (NSManagedObject に似ています)。

特定のセレクターが @dynamic で宣言されているかどうかを実行時に確認できますか? これは設計時のツールのための単なるコンパイラのトリックであり、実行時に失われますか、それともこれを検査する方法はありますか?

+ (BOOL) resolveInstanceMethod:(SEL)sel
{
    NSString *method = NSStringFromSelector(sel);
    // ideally I could also check here if the selector is @dynamic
    if ([method hasPrefix:@"set"] && [method rangeOfString:@":"].location == method.length -1) {
        class_addMethod([self class], sel, (IMP) dynamicSet, "v@:@");
        return YES;
    }
    else if ([method hasPrefix:@"get"] && [method rangeOfString:@":"].location == method.length -1) {
        class_addMethod([self class], sel, (IMP) dynamicGet, "v@:@");
        return YES;
    }

    BOOL value = [super resolveInstanceMethod:sel];
    return value;
}

また、私のクラスは NSDictionary をサブクラス化しますが、既存のメソッドに対して [super resolveInstanceMethod:sel] が呼び出されると、まだ false を返しますか?

4

1 に答える 1