Question

I'm building a static library to distribute to other folks to use in iOS apps, wherein I'd like to take advantage of of frameworks only if they have been included in the app by the users of my library. I've figured out how to compile the library so that it does not itself include any frameworks, but as soon as I try to use it in an app, it fails, because the library references frameworks that don't exist.

I'd rather not force my clients to load frameworks they don't need. Weak-linking frameworks is cool, but that just means that the framework doesn't have to be present on the system (e.g., for older versions of iOS); its support is still compiled into the binary. Better would be not to require the framework to be linked at all, and only use it if it is linked (optionally or not).

So, is there any way to detect that a framework is included in an iOS app at runtime, not just whether it's present on the system?

Was it helpful?

Solution

you can use

if (NSClassFromString(@"FrameworkClass") == nil) {
   // the framework is not available
} else {
   // the framework is avaiable
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top