[英]Generic Parameter 'self' could not be infered
I'm trying to convert bytes in values from a bluetooth device i'm using, but I'm getting Generic parameter 'Self' could not be inferred
on this and I don't know what it means 我正在尝试从正在使用的蓝牙设备转换值中的字节,但是我
Generic parameter 'Self' could not be inferred
对此得出Generic parameter 'Self' could not be inferred
,而且我不知道这意味着什么
var speed: UInt16 = 0
_ = withUnsafeBytes(of: &speed, {characteristic.value!.copyBytes(to: $0, from: 0...1)})
The error message is misleading. 该错误信息是令人误解的。 The actual problem is that
withUnsafeBytes
invokes the closure with a read-only buffer pointer to the raw bytes of the given argument. 实际的问题是
withUnsafeBytes
使用指向给定参数的原始字节的只读缓冲区指针调用关闭。 What you need is withUnsafeMutableBytes
: 您需要的是
withUnsafeMutableBytes
:
var speed: UInt16 = 0
_ = withUnsafeMutableBytes(of: &speed, {
characteristic.value!.copyBytes(to: $0, from: 0...1)
})
needed to change to 需要更改为
_ = withUnsafeMutableBytes(of: &speed, {
characteristic.value!.copyBytes(to: UnsafeMutuableBufferPointer(to: $0. count: 1), from: 0..<1)
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.