You can use NSClassFromString to get the Class and use the runtime library to execute the swizzling method. No header files. You just need to know the class name and method signature.
sel_getUid can be used when @selector(somePrivateMethod) gives your error about somePrivateMethod invalid selector (because the header is not available)
Code taken from my Xcode plugin
SEL sel = sel_getUid("codeDiagnosticsAtLocation:withCurrentFileContentDictionary:forIndex:"); Class IDEIndexClangQueryProviderClass = NSClassFromString(@"IDEIndexClangQueryProvider"); Method method = class_getInstanceMethod(IDEIndexClangQueryProviderClass, sel); IMP originalImp = method_getImplementation(method); IMP imp = imp_implementationWithBlock(^id(id me, id loc, id dict, IDEIndex *idx) { id ret = ((id (*)(id,SEL,id,id,id))originalImp)(me, sel, loc, dict, idx);
Bryan chen
source share