views:

18

answers:

1

Hi all,

Im currently trying to use some generated code from http://sudzc.com/ This code is not perfectly adapted to my web services, so I tried to add Categories to some of the generated classes and to exchange their implementations with the original ones using method_exchangeImplementations from "objc/runtime.h". (I could modify the generated code directly but I want to avoid it).

Here is the code I execute in MyAppAppDelegate - applicationDidFinishLaunching method

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);

As stated in my question, nearly all of those class_getClassMethod are returning nil... I used the debugger so I know 'theClass' is rightly set. The only method being found are those of the Soap class, which are both class level (+) methods. But from various examples on the net I concluded that it should work for the others as well...

Here are my includes for MyAppAppDelegate.m :

#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"

I tested my categories too and they work, I can call the category methods from a 'originalClass' object.

I suppose I'm doing something wrong, but I can't see what... Or maybe class_getClassMethod is indeed supposed to work only for class level methods ?

Ho and last thing, Im developing on the simulator, not the device :)

Any thought is welcome !

Thanks

P.B

A: 

Never mind, my mistake, class_getClassMethod is indeed supposed to work only for class level methods (as the name implies)

For instance methods, use... class_getInstanceMethod... :)

Sorry for the trouble

P.B

P.B