Reputation: 11
I got a issue while using swift-bridge-header feature to access c code framework(liblinphone). A struct LinphoneCallParams which defined in types.h that can be found in framework header files. And the struct definition is as following
typedef struct _LinphoneCallParams LinphoneCallParams;
When I try to define a parameter
var callPara: LinphoneCallParams?
in swift file, Xcode will show this error notice "Use of undeclared type 'LinphoneCallParams'". (No problem to access the other definition in this file, so the swift-briging-header file is without problem) Search the definition of _LinphoneCallParams, which is located in private.h that is not included in SDK. But the interesting thing is, if I use Object-C code to define this parameter
LinphoneCallParams *callParams = xxxxxxx();
Everything works correctly. I don't want to use Object-C code to implement this project. Any idea why this is happening?
Upvotes: 1
Views: 661
Reputation: 17382
The bridging compiler is quite aggressive in discarding things that it decides don't need to be there.
If struct _LinphoneCallParams
doesnt actually exist then the related typedef/typealias
wont make it into the generated header.
Compare these two examples.
struct _BoodleParams
exists:
And makes this:
class Thing {
var boodle = _BoodleParams(foo: 3, bar: 4)
var doodle = _BoodleParams(foo: 2, bar: 1)
}
Or this:
class Thing {
var boodle = BoodleParams(foo: 3, bar: 4)
var doodle = BoodleParams(foo: 2, bar: 1)
}
equally valid code.
However when you remove the need for the typedef
to exist in the counter part it is stripped during the bridging process.
Note that as long as the symbol _BoodleParams
exists somewhere in the compiled Objective-C the typedef will carry across in the counterpart.
In summary, the reason LinphoneCallParams
cant be instantiated in your Swift code is that either the symbol struct _LinphoneCallParams
isn't visible to the bridging system or it doesn't exist yet.
Upvotes: 1