简体   繁体   中英

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 . Specifically I'm unsure of how to properly construct the 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.

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.

See 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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