[英]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.