1. Why This Page?

This addendum lists all AVFoundation calls mentioned in the previous “Recording Video in SwiftUI” tutorial and drills down into their parameters and expected values so that you can memorise each API quickly.

2. AVCaptureSession

Method / PropertyParameterTypeExplanation
beginConfiguration()Marks the start of a batch-configuration block. Call before changing inputs/outputs or the preset to avoid mid-session glitches.
No parameters – the call itself is the “open brace.”
commitConfiguration()Applies all pending configuration changes atomically and resumes the session graph.
No parameters.
startRunning()Starts the capture pipeline asynchronously. Because it may block, dispatch on a background queue.
No parameters.
stopRunning()Stops the pipeline and releases hardware resources.
No parameters.
sessionPresetpresetAVCaptureSession.PresetDeclares the target quality and resolution (e.g. .high, .hd1920x1080, .hd4K3840x2160). Must be set between begin/commitConfiguration() calls.

3. AVCaptureDevice

Factory MethodParameterTypeExplanation
AVCaptureDevice.default(_:for:position:)deviceTypeAVCaptureDevice.DeviceTypeSpecific hardware family, e.g. .builtInWideAngleCamera, .builtInDualCamera.
mediaTypeAVMediaTypeUse .video or .audio.
positionAVCaptureDevice.PositionSelects .back, .front, or .unspecified.
Returns the first matching device or nil.

4. AVCaptureDeviceInput

InitialiserParameterTypeExplanation
AVCaptureDeviceInput(device:)deviceAVCaptureDeviceThe camera or microphone to wrap as a session input. Throwing initialiser because the device may be unavailable (permissions, ownership, etc.).
Initialiser produces an AVCaptureDeviceInput object.

5. AVCaptureMovieFileOutput

MethodParameterTypeExplanation
startRecording(to:recordingDelegate:)fileURLURLDestination for the encoded movie. Must be a file-scheme URL. If a file already exists it will be overwritten.
recordingDelegateAVCaptureFileOutputRecordingDelegateObject receiving progress and completion callbacks (fileOutput(_:didFinishRecordingTo:…)).
No return value – recording starts asynchronously.
stopRecording()Finishes writing. Triggers the delegate’s didFinishRecordingTo method once the file is finalised.
No parameters.
isRecordingBoolComputed property indicating whether a recording is in progress.

6. AVAssetWriter (advanced control)

Method / InitialiserParameterTypeExplanation
AVAssetWriter(outputURL:fileType:)outputURLURLLocation of the final file (must be writable).
fileTypeAVFileTypeContainer type, e.g. .mov, .mp4, .m4v.
Throws if the writer cannot be created.
add(AVAssetWriterInput)inputAVAssetWriterInputDescribes the media track (video/audio) and its compression settings (AVVideoCodecKey, bit-rate, etc.). Add one input per track.
No return; you must check canAdd(_:) first.
startSession(atSourceTime:)startTimeCMTimeThe timestamp corresponding to the first sample you will append. Typically .zero.
Call before appending samples.

7. Permissions Helpers

7.1 Camera / Microphone
CallParameterTypeExplanation
AVCaptureDevice.requestAccess(for:completionHandler:)mediaTypeAVMediaType.video or .audio.
completionHandler(Bool) -> VoidClosure executed on an arbitrary queue; parameter is true if permission was granted.
Returns void – the prompt appears automatically if needed.
7.2 Saving to Photos
CallParameterTypeExplanation
PHPhotoLibrary.shared().performChanges(_:completionHandler:)changes() -> VoidBlock that records the creation/deletion operations, e.g.
PHAssetChangeRequest.creationRequestForAssetFromVideo(atFileURL:).
completionHandler(Bool, Error?) -> VoidCalled when the change request has been committed to the photo library database.
Must be executed on the Photos permission queue.

8. SwiftUI Bridging Helpers

CallParameterTypeExplanation
UIViewRepresentable.makeUIView(context:)contextContextProvides the SwiftUI environment (coordinator, traitCollection, etc.). Return value is your UIKit view.
Override when embedding AVCaptureVideoPreviewLayer.
UIViewRepresentable.updateUIView(_:context:)uiViewUIViewThe existing view instance; update its state here (e.g. layer frame).
contextContextSame as above – includes animation info during view updates.
Called whenever SwiftUI detects state changes.