簡體   English   中英

二進制運算符+ =不能應用於類型&#39;UnsafeMutablePointer的操作數 <UInt8> &#39; 和&#39;Int&#39;

[英]binary operator += cannot be applied to operands of type 'UnsafeMutablePointer<UInt8>?' and 'Int'

在進行Swift轉換時,出現錯誤:

二進制運算符+ =不能應用於“ UnsafeMutablePointer?”類型的操作數 和'Int'

我的代碼:

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是一個可選值 您應該以安全的方式增加它。

正如這個答案所暗示的,您可以簡單地做到:

p = p.map { $0 + Int(avpkt.size) } 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM