Are local variables in Swift implicitly initialised to nil when used with UnsafeMutablePointer?

30 Views Asked by At
var cgImage: CGImage?
VTCreateCGImageFromCVPixelBuffer(pixelBuffer,
                                 options: nil,
                                 imageOut: &cgImage)
return cgImage

VTCreateCGImageFromCVPixelBuffer() takes in an UnsafeMutalePointer. Suppose an error occurs and it doesn't assign to cgImage. Is there a chance that I'll be returning an uninitialised variable? If so, I need to initialise the variable with nil:

var cgImage: CGImage? = nil

This is not a dupe of Do Optionals default to nil? because this question talks of UnsafeMutablePointers, and concerns local variables while that question talks of properties.

0

There are 0 best solutions below