Fix @MainActor warnings for startRunning/stopRunning#174
Open
Jack-sh1 wants to merge 1 commit into
Open
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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