From 887d627a756b8d9352288dcafc7ea5ff891033e8 Mon Sep 17 00:00:00 2001 From: Tobi Omotayo Date: Mon, 2 Dec 2024 17:10:19 +0100 Subject: [PATCH] use weak reference in legacy selfie view model to prevent retain cycle. --- .../SmileID/Classes/SelfieCapture/SelfieViewModel.swift | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Sources/SmileID/Classes/SelfieCapture/SelfieViewModel.swift b/Sources/SmileID/Classes/SelfieCapture/SelfieViewModel.swift index e9a4afe0..a3097ca0 100644 --- a/Sources/SmileID/Classes/SelfieCapture/SelfieViewModel.swift +++ b/Sources/SmileID/Classes/SelfieCapture/SelfieViewModel.swift @@ -118,7 +118,8 @@ public class SelfieViewModel: ObservableObject, ARKitSmileDelegate { } do { - try faceDetector.detect(imageBuffer: image) { [self] request, error in + try faceDetector.detect(imageBuffer: image) { [weak self] request, error in + guard let self else { return } if let error { print("Error analyzing image: \(error.localizedDescription)") self.error = error @@ -192,8 +193,8 @@ public class SelfieViewModel: ObservableObject, ARKitSmileDelegate { let userNeedsToSmile = livenessImages.count > numLivenessImages / 2 - DispatchQueue.main.async { [self] in - directive = userNeedsToSmile ? "Instructions.Smile" : "Instructions.Capturing" + DispatchQueue.main.async { + self.directive = userNeedsToSmile ? "Instructions.Smile" : "Instructions.Capturing" } // TODO: Use mouth deformation as an alternate signal for non-ARKit capture