我有一个如下所示的函数:
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) }