ios – Swift错误:无法将不可变值作为inout参数传递:’pChData’是’let’常量

前端之家收集整理的这篇文章主要介绍了ios – Swift错误:无法将不可变值作为inout参数传递:’pChData’是’let’常量前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个如下所示的函数
func receivedData(pChData: UInt8,andLength len: CInt) {
    var receivedData: Byte = Byte()
    var receivedDataLength: CInt = 0

    memcpy(&receivedData,&pChData,Int(len));  // Getting the error here
    receivedDataLength = len
    AudioHandler.sharedInstance.receiverAudio(&receivedData,WithLen: receivedDataLength)
}

得到错误

Cannot pass immutable value as inout argument: ‘pChData’ is a ‘let’ constant

虽然我在这里传递的参数都不是常量.我为什么要这个?

解决方法

您正在尝试访问/修改pChData参数,除非您将其声明为inout参数,否则您无法访问/修改该参数.了解有关inout参数 here的更多信息.请尝试使用以下代码.
func receivedData(inout pChData: UInt8,Int(len));
    receivedDataLength = len
    AudioHandler.sharedInstance.receiverAudio(&receivedData,WithLen: receivedDataLength)
}
原文链接:https://www.f2er.com/iOS/328395.html

猜你在找的iOS相关文章