Fix @MainActor warnings for startRunning/stopRunning#174
Fix @MainActor warnings for startRunning/stopRunning#174jack-old-archive wants to merge 1 commit into
Conversation
Add strict-concurrency compiler flag and mark ScannerViewController as @mainactor. Remove DispatchQueue.global dispatches around AVCaptureSession.startRunning() and stopRunning() which are @mainactor isolated in modern Swift, eliminating concurrency warnings reported in issue twostraws#105. Fixes twostraws#105
|
Before I merge this, I just wanted to check you've tried it in an actual project first – this isn't just a speculative "it seems to compile" change, right? |
Honest answer: I don't have access to a physical iOS device right now If someone with a device could verify there's no UI stutter when the |
|
I appreciate the help, but this code is quite finicky so I'd rather get it right on real devices. Thank you! |
Summary
Fix the @mainactor concurrency warnings reported in #105.
Changes
Package.swift-strict-concurrency=targetedcompiler flag viaunsafeFlagsto enable strict concurrency checking for the target.ScannerViewController.swiftScannerViewControllerwith@MainActor.DispatchQueue.global(qos: .userInteractive).asyncwrappers aroundcaptureSession.startRunning()andcaptureSession.stopRunning()-- these methods are@MainActor-isolated in modern Swift, so dispatching them to a background queue triggers concurrency warnings. Calling them directly on the main thread is the correct approach.Why this fix
AVCaptureSession.startRunning()andstopRunning()are@MainActormethods. The previous implementation dispatched them to a background queue (DispatchQueue.global), which triggers concurrency warnings when strict concurrency checking is enabled. By markingScannerViewControlleras@MainActorand calling these methods directly on the main thread, the warnings are eliminated and thread safety is guaranteed.Fixes #105