Is it possible to use the AppName-Prefix.pch file to import a given header file in all source files except one?
Problem:
I have followed the approach described here: https://stackoverflow.com/a/617559/1062572 to overwrite a C function call, namely the GCD dispatch_async
function.
Now I need to import the header file intercept.h
in all my source files and for that I tried to use the AppName-Prefix.pch file. However this also imports the header file in my implementation file intercept.m
. This cause an endless call loop because I try to call the original dispatch_async
in there.
Heres my header file intercept.h
:
#ifdef INTERCEPT
#define dispatch_async(queue, block) my_dispatch_async(queue, block)
#endif
And heres is my implementation file intercept.m
:
void my_dispatch_async(dispatch_queue_t queue, dispatch_block_t block) {
NSLog(@"\nBlock is enqueued!\n");
dispatch_async(queue, ^{
NSLog(@"\nBlock is dequeued!\n");
block();
NSLog(@"\nBlock has executed!\n");
});
}
Here is my Prefix.pch file:
#ifdef INTERCEPT
#import "Intercept.h"
#endif
How can I import the header file in all my sources, with the implementation file as the only exception? I hope it can be done without manually having to insert an import statement in every source file. And without writing a script to do it. ;)
One thing that confuses me even more is: Actually I have the implementation file in a compiled library (Testing.a), so why is the header file imported in it?
Even more information: I am writing a test framework that waits until all async tasks has completed before checking the results. That why I override dispatch_async. Any other suggestion is welcome. :)
Also I have noticed this answer: https://stackoverflow.com/a/617606/1062572 However it seems that this will not work on OSX, hence not iOS which is my target.
All these approaches will only overwrite the function call in my own source code. Actually I want it to overwrite it everywhere. However for this question I am satisfied if it works for my own source code.