简体   繁体   English

Linphone:类型UnsafePointer <MSList> 不符合协议序列

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

I am trying to loop through all calls in Linphone and find out the status for each call but I am unable to loop through the MSList. 我试图遍历Linphone中的所有呼叫并找出每个呼叫的状态,但是无法遍历MSList。

This is the code I am trying: 这是我正在尝试的代码:

for call in linphone_core_get_calls(lc) {

        }

This is the error it gives: Type 'UnsafePointer!' 这是它给出的错误:键入“ UnsafePointer!”。 (aka 'ImplicitlyUnwrappedOptional>') does not conform to protocol 'Sequence' (aka'ImplicitlyUnwrappedOptional>')不符合协议'Sequence'

You can do that in the following ways: 您可以通过以下方式做到这一点:

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
}

You can also use the forEach method with a C callback of type MSIterateFunc 您还可以将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
}

There are other ms_list_* methods you should check to achieve what you need. 您还应检查其他ms_list_*方法以实现所需的功能。 Be careful when working with MSList as you work directly with UnsfafePointers . 直接使用UnsfafePointers时,使用MSList时要小心。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM