2009-07-28 14 views

답변

3

IMP는 IMplementation Pointer로, 기본적으로 foo 길이와 같은 메시지 수신시 실행되는 것을 결정하는 후크입니다. 당신이 내려 앉고 더러워지기 전에는 보통 필요하지 않습니다. 일반적으로 선택자를 다루는 것이 더 쉽습니다.

6.1 IMP 란 무엇입니까? 오브젝티브 C 방법을 구현하는 함수

It's the C type of a method implementation pointer, a function 

포인터 . 이 ID를 반환하는 을 정의하고이 개 숨겨진 인수 자체를 받아 _cmd된다

typedef id (*IMP)(id self,SEL _cmd,...); 

6.2 How do I get an IMP given a SEL ? 

    This can be done by sending a methodFor: message : 

IMP myImp = [myObject methodFor:mySel]; 

6.3 How do I send a message given an IMP ? 

    By dereferencing the function pointer. The following are all 
    equivalent : 

[myObject myMessage]; 

    or 

IMP myImp = [myObject methodFor:@selector(myMessage)]; 
myImp(myObject,@selector(myMessage)); 

    or 

[myObject perform:@selector(myMessage)]; 

Objective C FAQ의 6.1 절에서.

msgSend는 다른 개체에서 원격 메시지를 호출하는 방법입니다. objc_msgSend (foo, @ selector (bar))는 [foo bar]와 거의 같습니다. 그러나 이것들은 모두 저수준 구현 세부 사항입니다. Objective C 코드를 위해 확장 된 호출을 사용해야하는 경우는 거의 없습니다. @selector를 사용하여 메서드를 얻고 performSelector : 모든 객체에서 호출 할 수 있기 때문입니다.