Skip to content

Fix @MainActor warnings for startRunning/stopRunning#174

Open
Jack-sh1 wants to merge 1 commit into
twostraws:mainfrom
Jack-sh1:fix/mainactor-warnings
Open

Fix @MainActor warnings for startRunning/stopRunning#174
Jack-sh1 wants to merge 1 commit into
twostraws:mainfrom
Jack-sh1:fix/mainactor-warnings

Conversation

@Jack-sh1
Copy link
Copy Markdown
Contributor

Summary

Fix the @mainactor concurrency warnings reported in #105.

Changes

Package.swift

  • Add -strict-concurrency=targeted compiler flag via unsafeFlags to enable strict concurrency checking for the target.

ScannerViewController.swift

  • Mark ScannerViewController with @MainActor.
  • Remove DispatchQueue.global(qos: .userInteractive).async wrappers around captureSession.startRunning() and captureSession.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() and stopRunning() are @MainActor methods. The previous implementation dispatched them to a background queue (DispatchQueue.global), which triggers concurrency warnings when strict concurrency checking is enabled. By marking ScannerViewController as @MainActor and calling these methods directly on the main thread, the warnings are eliminated and thread safety is guaranteed.

Fixes #105

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

@MainActor warnings when calling startRunning/stopRunning on background thread

1 participant