I had no luck to compile a sample code provided by apple with Xcode 16.0 beta 5.
ScreenCaptureKit demo (https://developer.apple.com/documentation/screencapturekit/capturing_screen_content_in_macos)
The part it is failling is,
streamOutput.capturedFrameHandler = { continuation.yield($0) }
And the error message is
Sending '$0' risks causing data races
Task-isolated '$0' is passed as a 'sending' parameter; Uses in callee may race with later task-isolated uses
Please enlighten me why this is an issue and how to avoid? Thanks in advance!
@Kyung, please use Feedback Assistant to submit a bug report regarding this issue. As @Claude31 pointed out, the sample fails to compile because the CapturedFrame
struct declared in line 14 of CaptureEngine.swift does not conform to the Sendable
protocol. You can work around the issue in the meantime by having CapturedFrame
conform to @unchecked Sendable
, for example:
/// A structure that contains the video data to render.
struct CapturedFrame: @unchecked Sendable