Swift application optional link to Mono

I am working on integrating some C-sharp code into a Swift application by using Mono. This is working fine but I want to make that integration optional. So, I changed the Mono.framework linking in Xcode to be optional and confirmed that's the result in the linker command line.

Now, my question is how can I check if the Mono.framework is actually available for use? I have only seen examples that check for Objective-C classes but none that deals with standard C function availability.

As far I can tell, I don't see anything special in the Mono headers that would help me and attempting to check if a function is available directly, such as mono_jit_init doesn't work because it is just checking the stub address.
I found a solution by using a little bit of C code:

Code Block
extern void mono_jit_init (const char *file) attribute((weak_import));
int isMonoAvailable(void)
{
return mono_jit_init != NULL;
}

and a header for the function as well that is included from the bridging header:
Code Block
extern int isMonoAvailable(void);

With the above in place, I can call from Swift to check availability:
Code Block
if isMonoAvailable() {
// do something with Mono
}

Swift application optional link to Mono
 
 
Q