SwiftInterfaceGeneratedHeader Bug

For calling swift api of a class to cpp , we need to include SwiftInterfaceGeneratedHeader to cpp file and then we can access swift class api in cpp . Signature of swift class with public apis will be added to the SwiftInterfaceGeneratedHeader.

We find an odd behaviour here . Signature of classes will be added to SwiftInterfaceGeneratedHeader in alphabetical order (swift class name alphabetically lower will be added first to generated header). If we have a swift class which is referenced by another swift class Api , then referenced class's name should be alphabetically lower that referee class , otherwise we will get a build error :- "Unknown class name".


public class A {
    public func funca () {
        print ("class A")
    }
}

public class B {
    public func funcb () {
        print ("class B")
    }
    
    public func funcb2 (pA:A) {
        pA.funca()
    }
    
    public func funcb3 (pC:C) {
        pC.funcc()
    }
}

public class C {
    public func funcc () {
        print ("class C")
    }
}

Cpp class where we include bridging header after turning on swift cpp interop :

class Test1 {
    
public:
    static void testfunc ();
};
#include "Test1.hpp"
#include "cppswiftinterop-Swift.h"


void
Test1::testfunc()
{
    
    
}

Here , we have three swift classes , Class A,B,C. And since we are including SwiftInterfaceGeneratedHeader in cpp , signature of these class will be added to the generated header . In this project , we are referencing Class A and Class C from Class B . And since A is alphabetically lower that B , it works fine (because signature of A in Generated header will be added before it is referenced by B). But since C is alphabetically above than B , it will through build error (Unknown type name 'C') , because Signature of C in Generated header will be added after it is referenced by class B).

If i rename Class C to Class AA then , it works fine.

Is this a bug in swift cpp interop?

Answered by DTS Engineer in 787435022

Is this a bug in swift cpp interop?

Yes. Normally I’d tell you to file a bug about this, but in this case I think there’s already one on file.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Accepted Answer

Is this a bug in swift cpp interop?

Yes. Normally I’d tell you to file a bug about this, but in this case I think there’s already one on file.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

SwiftInterfaceGeneratedHeader Bug
 
 
Q