I’m distributing a proprietary iOS SDK as a binary xcframework. The SDK consists of some options that require different, exterior dependencies (additionally xcframeworks) to work.
The exterior dependencies are fairly giant in measurement, and never many SDK shoppers use the options that require them. So we determined to distribute a model of the SDK that doesn’t embrace these options that require these large dependencies. Proper now, that is managed by a compilation flag, e.g.
#if EXTERNAL_DEPENDENCY
import SomeDependency
#endif
class SomeSDKComponent {
// ... different code
#if EXTERNAL_DEPENDENCY
func thisMethodUsesTheExternalDependencies() { ... }
#endif
// ... different code
}
If the SDK consumer desires to make use of the options that require these exterior dependencies, we would construct the SDK with the EXTERNAL_DEPENDENCY turned on.
In Xcode, these dependencies are set to "Do Not Embed", in order that the dimensions of the xcframework stays small, and we distribute the dependencies individually if the consumer wants them.

Whereas this works, I might nice if I can take away the compilation flag.
That’s, I would like to have the ability to compile the SDK with out all of the #ifs:
import SomeDependency
class SomeSDKComponent {
// ... different code
func thisMethodUsesTheExternalDependencies() { ... }
// ... different code
}
and I count on 3 issues:
- if the consumer by no means makes use of
thisMethodUsesTheExternalDependencies, their app ought to work no matter whether or not they included the exterior dependencies or not. - if the consumer calls
thisMethodUsesTheExternalDependencies, and consists of the exterior dependencies, their app ought to work as anticipated. - if the consumer calls
thisMethodUsesTheExternalDependencies, however doesn’t embrace the exterior dependencies, their app ought to crash when the decision is made.
How can I do that?
If I merely take away the #ifs, the consumer app will crash instantly after launch if they do not embrace the exterior dependencies. The error says
dyld[48209]: Library not loaded: @rpath/ExternalDependency.framework/ExternalDependency
Referenced from: <9F14FB92-BA4C-31E7-A4C9-7C04941377AA> /personal/var/containers/Bundle/Software/D81D65F6-81C5-4696-B1BD-854B39473EB2/ClientApp.app/Frameworks/MyProprietarySDK.framework/MyProprietarySDK
…adopted by an inventory of paths that it tried to seek for.
So it looks as if the app all the time tries to load these libraries upon launch.
Because the exterior dependencies are dynamically linked, my understanding is that the linking can theoretically occur when the primary time thisMethodUsesTheExternalDependencies known as, as an alternative of at the beginning of the app. Is there a construct setting for this?

