Configure Equatable isolation levels
mainThe @Equatable macro supports an isolation parameter to control the concurrency context of the generated == and hash(into:) methods. This parameter also applies to Hashable conformance if the type conforms to it.
Available options:
.nonisolated(default): The conformance can be called from any context..isolated: The conformance can only be called from within the actor's context..main(requires Swift 6.2+): The conformance is bound to the@MainActor. This allows the generated code to access@MainActorisolated properties synchronously.
// Nonisolated (default)
@Equatable(isolation: .nonisolated)
struct Person {
let name: String
}
// Isolated
@Equatable(isolation: .isolated)
struct Person {
let name: String
}
// Main (Swift 6.2+)
@Equatable(isolation: .main)
@MainActor
struct Person {
let name: String
}