簡體   English   中英

Linphone:類型UnsafePointer <MSList> 不符合協議序列

[英]Linphone: Type UnsafePointer<MSList> does not conform to protocol Sequence

我試圖遍歷Linphone中的所有呼叫並找出每個呼叫的狀態,但是無法遍歷MSList。

這是我正在嘗試的代碼:

for call in linphone_core_get_calls(lc) {

        }

這是它給出的錯誤:鍵入“ UnsafePointer!”。 (aka'ImplicitlyUnwrappedOptional>')不符合協議'Sequence'

您可以通過以下方式做到這一點:

let calls = linphone_core_get_calls(lc)

for index in 0..<ms_list_size(calls) {
    // MSList is a struct, data is a generic field containing what you need
    let data = ms_list_nth_data(calls, index)

    // bind the memory to the type you need
    // or just do what you need here
}

您還可以將forEach方法與MSIterateFunc類型的C回調MSIterateFunc

ms_list_for_each(calls) { element in 
    let element = element?.bindMemory(to: MSList.self, capacity: 1)
    let data = element?.pointee.data

    // bind the memory to the type you need
    // or just do what you need here
}

您還應檢查其他ms_list_*方法以實現所需的功能。 直接使用UnsfafePointers時,使用MSList時要小心。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM