【发布时间】:2019-01-09 01:17:02
【问题描述】:
我有一个项目,目前有一个 C 结构,它被定义为:
typedef struct IDList {
uint32_t listID;
uint32_t count;
uint32_t idArray[];
} __attribute__((packed, aligned(4))) IDList, *IDListPtr;
Objective-C 类中有一个方法可以返回一个 IDListPtr 给我。
我知道我可以:
let idListPtr = theIDManager.getIDList() // ObjC class that returns the struct
let idList = idListPtr.pointee // Get the IDList struct from the pointer
而且我知道结构的数组中有 idList.count 项,但是如何在 Swift 中访问该数组?
【问题讨论】:
-
其他帖子的问题是我无法在 Swift 中访问
idListPtr.pointee.idArray,它只允许我访问idListPtr.pointee.listID和idListPtr.pointee.count。所以我不知道如何应用该解决方案。