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.
AVCaptureSession
Method / Property | Parameter | Type | Explanation |
---|---|---|---|
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. | |||
sessionPreset | preset | AVCaptureSession.Preset | Declares the target quality and resolution (e.g. .high , .hd1920x1080 , .hd4K3840x2160 ). Must be set between begin /commitConfiguration() calls. |
AVCaptureDevice
Factory Method | Parameter | Type | Explanation |
---|---|---|---|
AVCaptureDevice.default(_:for:position:) | deviceType | AVCaptureDevice.DeviceType | Specific hardware family, e.g. .builtInWideAngleCamera , .builtInDualCamera . |
mediaType | AVMediaType | Use .video or .audio . | |
position | AVCaptureDevice.Position | Selects .back , .front , or .unspecified . | |
Returns the first matching device or nil . |
AVCaptureDeviceInput
Initialiser | Parameter | Type | Explanation |
---|---|---|---|
AVCaptureDeviceInput(device:) | device | AVCaptureDevice | The 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. |
AVCaptureMovieFileOutput
Method | Parameter | Type | Explanation |
---|---|---|---|
startRecording(to:recordingDelegate:) | fileURL | URL | Destination for the encoded movie. Must be a file-scheme URL. If a file already exists it will be overwritten. |
recordingDelegate | AVCaptureFileOutputRecordingDelegate | Object 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. | |||
isRecording | — | Bool | Computed property indicating whether a recording is in progress. |
AVAssetWriter
(advanced control)Method / Initialiser | Parameter | Type | Explanation |
---|---|---|---|
AVAssetWriter(outputURL:fileType:) | outputURL | URL | Location of the final file (must be writable). |
fileType | AVFileType | Container type, e.g. .mov , .mp4 , .m4v . | |
Throws if the writer cannot be created. | |||
add( | input | AVAssetWriterInput | Describes 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:) | startTime | CMTime | The timestamp corresponding to the first sample you will append. Typically .zero . |
Call before appending samples. |
Call | Parameter | Type | Explanation |
---|---|---|---|
AVCaptureDevice.requestAccess(for:completionHandler:) | mediaType | AVMediaType | .video or .audio . |
completionHandler | (Bool) -> Void | Closure executed on an arbitrary queue; parameter is true if permission was granted. | |
Returns void – the prompt appears automatically if needed. |
Call | Parameter | Type | Explanation |
---|---|---|---|
PHPhotoLibrary.shared().performChanges(_:completionHandler:) | changes | () -> Void | Block that records the creation/deletion operations, e.g. PHAssetChangeRequest.creationRequestForAssetFromVideo(atFileURL:) . |
completionHandler | (Bool, Error?) -> Void | Called when the change request has been committed to the photo library database. | |
Must be executed on the Photos permission queue. |
Call | Parameter | Type | Explanation |
---|---|---|---|
UIViewRepresentable.makeUIView(context:) | context | Context | Provides the SwiftUI environment (coordinator, traitCollection, etc.). Return value is your UIKit view. |
Override when embedding AVCaptureVideoPreviewLayer . | |||
UIViewRepresentable.updateUIView(_:context:) | uiView | UIView | The existing view instance; update its state here (e.g. layer frame). |
context | Context | Same as above – includes animation info during view updates. | |
Called whenever SwiftUI detects state changes. |