AVCapturePhotoCaptureDelegate is a protocol. You can read up more on protocols here https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/Protocols.html but the relevant information is this:
A protocol defines a blueprint of methods, properties, and other
requirements that suit a particular task or piece of functionality.
The protocol can then be adopted by a class, structure, or enumeration
to provide an actual implementation of those requirements. Any type
that satisfies the requirements of a protocol is said to conform to
that protocol.
What this function capturePhoto is asking you to do is to pass an Object that conforms to the protocol. By convention we call this a delegate (think of it as a series of functionality that's delegated to another object).
It's essentially a call back. capturePhoto "knows" (because you are conforming to the protocol) that the delegate will contain the functions that it needs to call so that you can do your processing of the image.
To successfully pass the delegate, you need to define an object which conforms to the protocol and pass an instance of that object to the function as the delegate. You MUST declare the methods that you intend to use from the protocol. Here's a partial EXAMPLE - don't copy paste this, you'll need to work out what you need for your implementation.
class PhotoDelegate() : AVCapturePhotoCaptureDelegate {
optional func capture(_ captureOutput: AVCapturePhotoOutput,
didFinishProcessingPhotoSampleBuffer photoSampleBuffer: CMSampleBuffer?,
previewPhotoSampleBuffer: CMSampleBuffer?,
resolvedSettings: AVCaptureResolvedPhotoSettings,
bracketSettings: AVCaptureBracketedStillImageSettings?,
error: Error?) {
// YOUR CODE TO PROCESS THE IMAGE GOES HERE
}
}
let myPhotoDelegate = PhotoDelegate()
// myPhotoDelegate is what you'll pass to the delegate: parameter
I would very carefully note that according to the documentation for AVCapturePhotoCaptureDelegate the methods are all OPTIONAL at compile time, which actual methods need to be implemented will depend on what settings you pass.
Which delegate methods the photo output calls depends on the photo
settings you initiate capture with. All methods in this protocol are
optional at compile time, but at run time your delegate object must
respond to certain methods depending on your photo settings: