【发布时间】:2019-08-30 12:50:32
【问题描述】:
我正在使用 dlopen 函数从 swift 包中的 .dylib 导入 c 函数。 c 函数(即上行函数)将返回结构。为了从 swift 调用 c 函数,我需要创建 c 函数的类型别名。
C 结构
typedef struct Uplink { long _handle; } UplinkRef;
C 函数声明
extern UplinkRef uplink(UplinkConfig p0, char** p1);
uplink 函数正在返回 UplinkRef 结构。
Swift 中的 UplinkRef 结构
struct UplinkRef{
var _handle = -1
}
所以,我必须在 swift 中创建 typealias 以便我可以调用 c 函数
typealias uplink = @convention(c) ()->UplinkRef
1) 我如何将结构(即 UplinkRef)定义为 typealise 的返回类型?
2) 如何将结构(即 UplinkRef)定义为 typealias 的参数?
【问题讨论】:
标签: swift struct type-alias