[英]binary operator += cannot be applied to operands of type 'UnsafeMutablePointer<UInt8>?' and 'Int'
While doing Swift conversion, I got an error: 在进行Swift转换时,出现错误:
binary operator += cannot be applied to operands of type 'UnsafeMutablePointer?' 二进制运算符+ =不能应用于“ UnsafeMutablePointer?”类型的操作数 and 'Int' 和'Int'
My code: 我的代码:
var avpkt = AVPacket()
var p : UnsafeMutablePointer<UInt8>? = nil
avpkt.data = UnsafeMutablePointer<UInt8>(mutating: inbuf)
p = avpkt.data
p += Int(avpkt.size) // error at this line
p
is an optional value . p
是一个可选值 。 You should increment it in a safe way. 您应该以安全的方式增加它。
As this answer suggests, you can simply do: 正如这个答案所暗示的,您可以简单地做到:
p = p.map { $0 + Int(avpkt.size) }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.