Protocol
클래스는 Leopard/ObjC 2.0 이후로 더 이상 사용되지 않습니다. * 따라서 여기에는 메소드가없고 현재 문서가 없습니다. 프로토콜과 상호 작용하는 유일한 방법은 런타임 기능을 사용하는 것입니다.
프로토콜의 메서드 목록에 포함 된 구조체도 개체가 아니므로 어쨌든 NSArray
에 들어갈 수 없습니다.
protocol_copyMethodDescriptionList()
에서 반환 된 배열을 처리하는 것은 그리 힘들지 않습니다. 당신은 단지 free()
을 기억해야합니다. 특정 선택기를 염두에 둔 경우 protocol_getMethodDescription()
을 사용하여 프로토콜을 확인할 수도 있습니다.이 경우 어떤 메모리 관리도 필요하지 않습니다. 예를 들면 :
BOOL method_description_isNULL(struct objc_method_description desc)
{
return (desc.types == NULL) && (desc.name == NULL);
}
const char * procure_encoding_string_for_selector_from_protocol(SEL sel, Protocol * protocol)
{
static BOOL isReqVals[4] = {NO, NO, YES, YES};
static BOOL isInstanceVals[4] = {NO, YES, NO, YES};
struct objc_method_description desc = {NULL, NULL};
for(int i = 0; i < 4; i++){
desc = protocol_getMethodDescription(protocol,
sel,
isReqVals[i],
isInstanceVals[i]);
if(!method_description_isNULL(desc)){
break;
}
}
return desc.types;
}
* 사실, 보인다 이름이 지금 Class
단지의 별칭입니다 (런타임 참조에서 a note 기준).