Arguments passed to a function are by default immutable inside the function.
You need to make a variable copy (compatible with Swift 3):
func receivedData(pChData: UInt8, andLength len: CInt) { var pChData = pChData var receivedData: Byte = Byte() var receivedDataLength: CInt = 0 memcpy(&receivedData, &pChData, Int(len));
or, with Swift 2, you can add var to the argument:
func receivedData(var pChData: UInt8, andLength len: CInt) { var receivedData: Byte = Byte() var receivedDataLength: CInt = 0 memcpy(&receivedData, &pChData, Int(len));
The third option, but this is not what you are asking for: make the inout argument. But it will also mutate pchData outside of func, so it looks like you don't want this here - this is not your question (but I could read it wrong, of course).
source share