2

I'm wondering if it is possible to forward a class method to a different instance. I've had a look at the docs and all the methods shown there are instance level methods. So is there a way I can negotiate and forward a class or static method?

Just for some more Information, the Vision I have is to instead of doing [ASingleton sharedInstance] somemethod] I wish to call someMethod on ASingleton directly.

Community
  • 1
  • 1
cream-corn
  • 1,820
  • 14
  • 26
  • @cream-com, I think that method swizzle - is your solution. for a first glance – gaussblurinc Mar 07 '14 at 06:16
  • [see here](http://cocoadev.com/MethodSwizzling) – gaussblurinc Mar 07 '14 at 06:20
  • @gaussblurinc if only that blog post had some syntax highlighting and some structure it would be much easier to read! but thanks for the article! – cream-corn Mar 07 '14 at 06:26
  • @cream-com, sorry, but google place it on first position :) – gaussblurinc Mar 07 '14 at 06:31
  • @gaussblurinc I'm sorry but I think this won't help me? if you look at the code example `orig_method = class_getInstanceMethod(aClass, orig_sel); alt_method = class_getInstanceMethod(aClass, alt_sel);` they both use `getInstanceMethod` :( – cream-corn Mar 07 '14 at 06:33
  • 1
    @cream-corn you can use `class_getClassMethod(Class cls, SEL name)`,see `runtime.h` – johnMa Mar 07 '14 at 06:57
  • Have a look at this http://nshipster.com/method-swizzling/ – sbarow Mar 07 '14 at 07:51
  • Method Swizzling is different for message forwarding, Im not interested in changing the implementation of a (class) method, i want to negotiate/forward a message sent to a class (not instance) and forward that message to an Instance. – cream-corn Mar 10 '14 at 01:56

0 Answers0