Check for framework's existence at compile time? Check for framework's existence at compile time? objective-c objective-c

Check for framework's existence at compile time?


You can check for the presence of a header file using the __has_include language extension.http://clang.llvm.org/docs/LanguageExtensions.html#include-file-checking-macros

However, that only tells you if the header file is installed. It can't tell you if "Link Binary With Libraries" has linked to its framework.


I recommend reading the Mac Developer Library : Framework Programming Guide (which includes a section on Weak Linking).

  1. What do you mean by "exists" or "included in the project"? Do you mean added to the "Link Binary With Libraries" build phase (as described by Including Frameworks)? All that does is affect the linking, not the compilation, build phase. To see this, build. Then, search for -framework in the build log of Xcode's Log Navigator.

    So, yes, if you want to affect the compilation of the code you provided, you could manually define the macro _MY_FRAMEWORK_EXISTS.

  2. I don't really understand what you are trying to do. Can you explain what you want at a higher level? Perhaps, there's a better way to go about it.

    "Minimal overhead" is nice, but too much magic might be confusing. For example, Xcode's magic hides what really happens when including a framework.

    I also recommend checking out how the Facebook SDK for iOS works for high & low-level ideas. It might do the kinds of things you want to do.