swift - 在 Swift 中使用 Objective C/C

标签 swift

我在 swift 中使用 objective-c /c 库时遇到问题。

    for i in results {
        print(i.interface.index)
    }

当我尝试访问对象的属性“interface”时,我从 Swift 收到此错误:

“AnyObject”类型的值没有成员接口(interface)。

但是“i”是一个 MidiBusInterface 对象,我可以在这里查看:

Screenshot

@interface MidiBusInterface : NSObject
{
    @public
    MIDIBUS_INTERFACE* interface;
}

typedef struct midibus_interface
{
   uint8_t index;

   eMidiBusInterfaceType type;

   eMidiBusInterfaceMode mode;

   uint8_t transport;

   char* ident;

   bool_t enabled;

   bool_t network_connections;

   uint64_t event_count;  

   uint64_t transport_delay_average_mt;

   uint64_t transport_delay_average_deviation_mt;

   bool_t clock_running;                // clock is running
   uint64_t start_tick_count;           // total number of ticks since start
   uint64_t cont_tick_count;            // ticks since continue (or start)
   float current_bpm;                   // current bpm measured
   float  min_bpm, max_bpm, avg_bpm;    // min/max/avg bpm this clock run
   float bpm_average_deviation_percent; // bpm standard deviation %

   bool_t present;                           // interface present
   uint64_t tick_anchor_mt;                  // timestamp of start/cont event
   uint64_t last_tick_timestamp_received_mt; // timestamp of last tick
   bool_t is_owner;                          // set to true if app owns        interface
} MIDIBUS_INTERFACE;

有什么线索吗?

非常感谢!

最佳答案

结果是 Objective C 集合吗?您需要将结果转换为 MidiBusInterface 类型,例如:

for i in results as? [MidiBusInterface] {
        print(i.interface.index)
    }

关于swift - 在 Swift 中使用 Objective C/C,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33356705/

相关文章:

ios - UICollectionView 单元格间距不再起作用

swift - 如何从数组中释放所有引用元素?

ios - 它是如何工作的scrollToRow(位于:at:animated:) in swift?

ios - 无法切换 UISwitch 的状态

ios - Xcode 10 代码完成占位符 — "T"是什么?

optimization - 使用 "if let"解包堆栈对象(例如结构)

if-statement - Swift 'If' 语句的多个条件?

swift - 将 NSDecimalNumbers 转换为负数

ios - 在 Swift 中更改 MKMapView 上的图钉图像

ios - 选项卡栏上的选定索引不适用于 Swift