1

현재 생성 된 코드를 사용하려고합니다 http://sudzc.com/ 이 코드는 내 웹 서비스에 완전히 적용되지 않았으므로 생성 된 클래스 중 일부에 카테고리를 추가하려고했습니다. "objc/runtime.h"의 method_exchangeImplementations를 사용하여 구현 된 객체를 원래 객체와 교환 할 수 있습니다. (나는 직접 생성 된 코드를 수정할 수 있지만 그것을 피하고 싶다). 나는 '하는 theClass'를 알 수 있도록 아래 applicationDidFinishLaunching 방법은 거의 그 class_getClassMethod 모든 전무를 반환하는, 내 질문에 명시된 바와 같이class_getClassMethod는 종종 nil을 반환합니다 (클래스 수준의 메서드에서만 작동하는 것처럼 보입니다)

Class theClass = [CBMayaIPhoneUser class]; 
Method originalMethod = class_getClassMethod(theClass, @selector(initWithNode:)); 
Method categoryMethod = class_getClassMethod(theClass, @selector(initWithAllStringNode:)); 
method_exchangeImplementations(originalMethod, categoryMethod); 

theClass = [Soap class]; 
originalMethod = class_getClassMethod(theClass, @selector(getNodeValue:withName:)); 
categoryMethod = class_getClassMethod(theClass, @selector(getHrefNodeValue:withName:)); 
method_exchangeImplementations(originalMethod, categoryMethod); 

theClass = [SoapRequest class]; 
originalMethod = class_getClassMethod(theClass, @selector(send)); 
categoryMethod = class_getClassMethod(theClass, @selector(sendIgnoringCertificate)); 
method_exchangeImplementations(originalMethod, categoryMethod); 
originalMethod = class_getClassMethod(theClass, @selector(connectionDidFinishLoading:)); 
categoryMethod = class_getClassMethod(theClass, @selector(connectionDidFinishLoadingAndSentBody:)); 
method_exchangeImplementations(originalMethod, categoryMethod); 

... 난 디버거를 사용 - 여기

내가 MyAppAppDelegate에서 실행 코드입니다 바르게 설정하십시오. 발견되는 유일한 메소드는 클래스 레벨 (+) 메소드 인 Soap 클래스의 메소드입니다. ,

#import "MyAppAppDelegate.h" 
#import "RootViewController.h" 
#import "MyGlobalVariables.h" 
#import "MyWebServiceExample.h" 
#import "Soap+Href.h" 
#import "SoapRequest+Certificate.h" 
#import "CBMayaIPhoneUser+AllString.h" 
#import "objc/runtime.h" 

내가 너무 내 범주를 시험하고 작동 : 그러나 여기

이 ... 난 그것뿐만 아니라 다른 사람을 위해 일해야한다는 결론을 내렸다 그물에 다양한 예에서 제는 MyAppAppDelegate.m을 위해 포함 'originalClass'객체에서 카테고리 메소드를 호출 할 수 있습니다.

나는 뭔가 잘못하고 있다고 생각하지만, 나는 무엇을 볼 수 없습니다 ... 아니면 class_getClassMethod 실제로 클래스 수준의 메서드에서만 작동하도록되어 있습니까?

호와 마지막, 임 시뮬레이터 개발

가 아닌 장치 :

어떤 생각을 환영합니다!

감사

PB

답변

9

신경 쓰지 마, 내 실수는, class_getClassMethod은 참으로 인스턴스 메소드, 사용 ... class_getInstanceMethod를 들어

(이름이 의미하는 바와 같이)에만 클래스 수준의 방법을 작동하도록되어 ... :)

문제에 대한

죄송합니다

PB

관련 문제