【问题标题】:Linphone: Type UnsafePointer<MSList> does not conform to protocol SequenceLinphone:类型 UnsafePointer<MSList> 不符合协议序列
【发布时间】:2018-01-08 13:33:14
【问题描述】:
我正在尝试遍历 Linphone 中的所有呼叫并找出每个呼叫的状态,但我无法遍历 MSList。
这是我正在尝试的代码:
for call in linphone_core_get_calls(lc) {
}
这是它给出的错误:
键入“不安全指针!” (aka 'ImplicitlyUnwrappedOptional>') 不符合协议'Sequence'
【问题讨论】:
标签:
ios
loops
call
voip
linphone
【解决方案1】:
您可以通过以下方式做到这一点:
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 回调一起使用
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_* 方法以实现您的需要。使用MSList 时要小心,因为您直接使用UnsfafePointers。