Let's say I have a @MainActor isolated type that provides efficient access to an underlying data set:
struct Thing: Identifiable {
let id = UUID()
// etc...
}
@MainActor
final class GiantStore {
var numberOfItems: Int { /* implementation omitted */ }
func item(at index: Int) -> Thing { /* implementation omitted */ }
}
Which I browse using a View generic over some Collection type.
@MainActor
struct ThingBrowser<T: RandomAccessCollection>: View where T.Element == Thing {
// etc...
}
Pre Swift Concurrency I would have written a simple Collection wrapper that handled accessing data within the underlying store without incurring a copy.
@MainActor struct GiantStoreCollection: RandomAccessCollection {
let store: GiantStore
var startIndex: Int { 0 }
var endIndex: Int { store.numberOfItems + 1 } // ERROR: Main actor-isolated instance methods cannot be used to satisfy nonisolated protocol requirement
func index(after i: Int) -> Int { i + 1 }
subscript(position: Int) -> Thing { store.item(at: position) } // ERROR: Main actor-isolated instance methods cannot be used to satisfy nonisolated protocol requirement
}
Now however, this fails because you can neither 1) access the isolated store synchronously, nor 2) satisfy non-isolated protocol requirements with an isolated instance method.
Is there a feature/technique I've missed that somehow makes this possible, or some kind of evolution in the works that would somehow permit overriding the isolation context of a protocol?