简体   繁体   English

Swift 中的 C 结构

[英]C Struct in Swift

I'm attempting to use amazon-kinesis-video-streams-webrtc-sdk-c in a Swift project however I'm unsure of how to create a SignalingClientInfo struct .我正在尝试在 Swift 项目中使用amazon-kinesis-video-streams-webrtc-sdk-c但是我不确定如何创建SignalingClientInfo struct Specifically I'm unsure of how to properly construct the clientId :具体来说,我不确定如何正确构造clientId

var signalingClientInfo = SignalingClientInfo(
    version: UINT32(SIGNALING_CLIENT_INFO_CURRENT_VERSION),
    clientId: clientId,
    loggingLevel: UINT32(1)
)

Kind of annoying, but fixed-sized arrays in C like clientId are imported into Swift as tuples.有点烦人,但像clientId这样的 C 中固定大小的数组作为元组导入到 Swift 中。

There's on-going discussions on adding proper fixed-size arrays to Swift, but in the mean time, there are implementation-dependent tricks you can use to construct large tuples from arrays.关于向 Swift 添加适当的固定大小数组的讨论正在进行中,但与此同时,您可以使用依赖于实现的技巧从数组构造大元组。

See https://oleb.net/blog/2017/12/swift-imports-fixed-size-c-arrays-as-tuples/https://oleb.net/blog/2017/12/swift-imports-fixed-size-c-arrays-as-tuples/

Edit: it looks like the layout of homogeneous tuples is guaranteed .编辑:看起来同构元组的布局是有保证的 So this is safe, just annoying.所以这是安全的,只是烦人。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM