Objective-c: Repleace resolveClassMethod and resolveInstanceMethod with reflection

Reflection - objective-cAfter Apple LLVM compiler 3.0 update, my classes with resolveClassMethod and resolveInstanceMethod methods are not working (XCode compile them but i can see errors at runtime).

Fortunately, you can use the new compiler by Apple replacing the method by reflection!

Follow this instructions:

First, import the reflection header and define your selector (remember, insert a : symbol for any argument… not forget the argument’s name if you have many arguments)

#import <objc/message.h>
SEL selector = NSSelectorFromString(@"MyMethod:"); 
SEL selector = @selector(@"MyMethod:");

Now, repleace your resolveClassMethod:

if([MyClass class] resolveClassMethod:selector])


if(class_getClassMethod([MyClass class], selector) != nil)

or repleace your resolveInstanceMethod:

if([MyClass class] resolveInstanceMethod:selector])


if(class_getInstanceMethod([MyClass class], selector) != nil)

Good Luck!!!

  1. objectivecrizzo ha rebloggato questo post da g8production
  2. postato da g8production
blog comments powered by Disqus