@dynamic 키워드 (NSManagedObject와 유사)를 사용하여 선언 된 속성을 지원하는 사전을 동적으로 구현하고 있습니다.런타임에 속성이 @dynamic으로 선언되었는지 확인하는 방법
런타임시 특정 선택기가 @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, "[email protected]:@");
return YES;
}
else if ([method hasPrefix:@"get"] && [method rangeOfString:@":"].location == method.length -1) {
class_addMethod([self class], sel, (IMP) dynamicGet, "[email protected]:@");
return YES;
}
BOOL value = [super resolveInstanceMethod:sel];
return value;
}
, [슈퍼 resolveInstanceMethod : SEL]를 내 클래스의 서브 클래스는 NSDictionary하지만 기존의 방법에 대해 호출됩니다 - 아직도 false를 반환?
'G'와'S' 속성 속성은 커스텀 getter와 setter 이름이 정의되어 있다면 그것을 포함합니다. * Objective-C 런타임 프로그래밍 가이드 *의 [선언 된 속성] (http://developer.apple.com/library/ios/DOCUMENTATION/Cocoa/Conceptual/ObjCRuntimeGuide/Articles/ocrtPropertyIntrospection.html#//apple_ref/)을 참조하십시오. doc/uid/TP40008048-CH101-SW1). –
@robmayoff 사실,하지만 그 값을 얻을 수 있다면 이미 속성 이름을 가지고 있습니다. 질문은 선택자에서 덜 명확한 속성으로 이동하는 방법을 묻는 것입니다. –
'class_copyPropertyList '를 사용하여 모든 속성을 반복하고 각각의'G'와'S'를 검사 할 수 있습니다. 하지만 init의 모든 속성을 반복하고 각 동적 속성에 접근자를 추가하는 것이 좋습니다. –