Hi there,
I am endeavoring with actor-facade for spotlight indexing.
In apple doc, in description of a CSSearchableIndex
class, I read that
>>> Modify custom CSSearchableIndex objects only on one thread or task at a time. It’s a programming error to access a custom index from multiple threads simultaneously.
Oh! It seems that is an ideal situation to use actor as a facade to control an access to CSSearchableIndex
object.
But, when I wrote a simple actor facade for indexing, I saw this:
actor SpotlightIndex {
private let searchableIndex: CSSearchableIndex
init(searchableIndex: CSSearchableIndex) {
self.searchableIndex = searchableIndex
}
func indexItems(_ items: sending [CSSearchableItem]) async throws {
try await searchableIndex.indexSearchableItems(items) /// ❌ Sending 'self.searchableIndex' risks causing data races; this is an error in the Swift 6 language mode
/// Sending 'self'-isolated 'self.searchableIndex' to nonisolated instance method 'indexSearchableItems(_:)' risks causing data races between nonisolated and 'self'-isolated uses
}
func deleteItems(with identifiers: sending [String]) async throws {
try await searchableIndex.deleteSearchableItems(withIdentifiers: identifiers) /// ❌ Sending 'self.searchableIndex' risks causing data races; this is an error in the Swift 6 language mode
/// Sending 'self'-isolated 'self.searchableIndex' to nonisolated instance method 'deleteSearchableItems(withIdentifiers:)' risks causing data races between nonisolated and 'self'-isolated uses
}
}
These compiler errors seem actual - nonisolated functions take actor member as a parameter (because of implicit self
access), and nobody knows how does this member changes inside nonisolated func...
Is it possible to resolve this error someway?