简体   繁体   English

二进制运算符+ =不能应用于类型&#39;UnsafeMutablePointer的操作数 <UInt8> &#39; 和&#39;Int&#39;

[英]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.

相关问题 二元运算符%不能应用于UInt32和int类型的操作数 - binary operator % cannot be applied to operands of type UInt32 and int 二进制运算符&#39;==&#39;不能应用于类型为&#39;String&#39;和&#39;UInt32&#39;的操作数 - Binary operator '==' cannot be applied to operands of type 'String' and 'UInt32' 二进制运算符&#39;==&#39;不能应用于类型&#39;(Any)-&gt; Int&#39;和&#39;Int&#39;的操作数 - Binary operator '==' cannot be applied to operands of type '(Any) -> Int' and 'Int' 二进制运算符.. &lt;不能应用于操作数“ Int”和“ Int?” - Binary operator ..< cannot be applied to operands 'Int' and 'Int?' 二进制运算符*不能应用于Int和CGFloat类型的操作数 - Binary operator * cannot be applied to operands of type Int and CGFloat 二进制运算符-不能应用于字符串类型的操作数! 和诠释 - Binary operator - cannot be applied to operands of type String! and Int 二进制运算符“&”不能应用于类型为“ SCNetworkReachabilityFlags”和“ Int”的操作数 - Binary operator '&' cannot be applied to operands of type 'SCNetworkReachabilityFlags' and 'Int' 二进制运算符&#39;&gt; =&#39;不能应用于&#39;Any&#39;和&#39;Int&#39;类型的操作数 - Binary operator '>=' cannot be applied to operands of type 'Any' and 'Int' 二进制运算符&#39;&lt;&#39;不能应用于使用Guard的&#39;CGPoint&#39;和&#39;Int&#39;类型的操作数 - Binary operator '<' cannot be applied to operands of type 'CGPoint' and 'Int' Using Guard 二元运算符 + 不能应用于 CGfloat int 类型的操作数 - Binary Operator + Cannot be Applied to Operands of Type CGfloat int
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM