I'm writing a Swift app that uses the Blackmagic ATEM SDK, which is written in C++. The SDK has two files: BMDSwitcherAPI.h
and BMDSwitcherAPIDispatch.cpp
, and I've compiled them into an Xcode package called BlackmagicSDK
.
However, I can't declare variables with types that are declared as C++ classes, only those declared using typedef
. For example, I can't declare a constant of type IBMDSwitcher
, which is declared like this:
// BMDSwitcherAPI.h
class BMD_PUBLIC IBMDSwitcher : public IUnknown
{
public:
...
}
If I try to use it in Swift, this happens:
// Switcher.swift
import BlackmagicSDK
struct Switcher {
let interface: IBMDSwitcher // Error: "Cannot find type 'BMDSwitcher' in Scope"
}
There are some classes (about 170) that are declared like this:
// BMDSwitcherAPI.h
class IBMDSwitcherAudioHeadphoneOutput;
class IBMDSwitcherAudioHeadphoneOutputCallback;
...
I can access a small subset of these (around 10) but there doesn't seem to be any pattern to the ones I can access, except they're all declared using the simpler syntax instead of the full class declaration.
I can also access types like BMDSwitcherInputID
and BMDSwitcherVideoCodec
, which are declared like this:
// BMDSwitcherAPI.h
typedef int64_t BMDSwitcherInputId;
typedef uint32_t BMDSwitcherVideoCodec;
My best theory for this is that these types are aliases of C++ standard library types that Swift understands. I still don't fully understand what typedef
actually does, though.
My final clue is the global function that returns a class for connecting to the ATEM hardware over the network, which I can access. Xcode shows the return type as an Opaque Pointer!
. The closest I found online is OpaquePointer
, which Apple says is "used to represent C pointers to types that cannot be represented in Swift". I don't know if that's relevant or just a red herring, though.