Search code examples
objective-cswiftextern

Use extern "C" in Swift?


I wondered, is there an alternative to extern "C" in Swift? I want to write a simple Unity plugin, and as an Obj-C noob I'd like to do it in Swift if possible. Right now I have a very basic Obj-C code to show UIAlertView using

extern "C" 
{ 
    void _addAlert() 
    //Whatever
} 

And in Unity it's hooked up with

private static extern void _addAlert()
{
    //Same whatever
} 

I'm looking for a way to use Swift instead of Obj-C. Is that possible?


Solution

  • Top-level functions from Swift cannot be used from C/Objective-C. So obviously you will not be able to link to it from C/Objective-C.