1

While doing Swift conversion, I got an error:

binary operator += cannot be applied to operands of type 'UnsafeMutablePointer?' and '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
Tamás Sengel
  • 55,884
  • 29
  • 169
  • 223
nilesh
  • 55
  • 10

1 Answers1

0

p is an optional value. You should increment it in a safe way.

As this answer suggests, you can simply do:

p = p.map { $0 + Int(avpkt.size) } 
Tamás Sengel
  • 55,884
  • 29
  • 169
  • 223