Context
I have a Mac app that uses the old QuickLook protocols: QLPreviewPanelDataSource
and QLPreviewPanelDelegate
. You select a row in an NSTableView
, hit the spacebar, and you get the QuickLook preview. Standard stuff:
@MainActor
final class SomeController: NSTableViewDataSource, QLPreviewPanelDataSource
{
private var tableView: NSTableView
func numberOfPreviewItems(in panel: QLPreviewPanel!) -> Int {
return tableView.numberOfSelectedRows
}
}
Problem
I'm adopting Actors and Swift Concurrency in this app. SomeController
is now assigned to @MainActor
as it should be, since it controls UI. But this brings warnings for the -numberOfPreviewItems()
implementation:
Main actor-isolated instance method 'numberOfPreviewItems(in:)' cannot be used to satisfy nonisolated protocol requirement
QLPreviewPanelDataSource
is not decorated with @MainActor
, which would obviously solve the problem. I cannot simply mark the function nonisolated
, since it touches tableView
, which IS isolated to the Main Actor. And I cannot await an access, since the protocol method does not support concurrency.
Everything works fine, of course, but having 30-some spurious build warnings is a giant distraction.
Question
What is the correct way to silence these warnings assuming:
Apple will never update the protocols with the
@MainActor
decoration. (Radars to do so are unanswered for years.)I want to keep the
Strict Concurrency Checking
build setting set tocomplete
to catch other, legitimate issues.
QLPreviewPanelDataSource
conformance into a dedicated data-source type that isn't actor isolated, and set properties on it from withinSomeController
(e.g., on selection, assigntableView.numberOfSelectedRows
as a property on the data source so it doesn't need to touchtableView
; etc.). – Active@preconcurrency
macro? That’s what it’s for, namely frameworks not yet updated forSendable
. See WWDC 2022 Eliminate data races using Swift Concurrency: “you can temporarily disable the Sendable warnings for types that come from that module using the @preconcurrency attribute.” – Pula@preconcurrency
on theimport quartz
line. Xcode tells me it’s unused and the warnings continue. – Transverse@preconcurrency
silencesSendable
warnings, but not this actor isolation issue. I also tried putting thisQLPreviewPanelDataSource
conformance in an extension in its own file and tried overriding thestrict-concurrency
build setting in the build phases, but even that didn’t seem to work. Interesting question. – Pula