Fix some isolation errors when compiling with Swift 6.4. (#6148)

* Fix some isolation errors when compiling with Swift 6.4.

* Update the Design Tokens dependency to include Sendable conformances.
This commit is contained in:
Doug
2026-09-10 15:22:53 +01:00
committed by GitHub
parent a150df584d
commit 4608a63e29
11 changed files with 28 additions and 27 deletions
@@ -7,11 +7,12 @@
//
import CompoundDesignTokens
import Synchronization
import UIKit
public extension UIColor {
/// The colours used by Element as defined in Compound Design Tokens.
static let compound = CompoundUIColors()
nonisolated static let compound = CompoundUIColors()
}
/// The colours used by Element as defined in Compound Design Tokens.
@@ -20,7 +21,7 @@ public extension UIColor {
/// The object needs to be nonisolated.
@Observable
@dynamicMemberLookup
public final nonisolated class CompoundUIColors {
public final nonisolated class CompoundUIColors: Sendable {
/// The base colour tokens that form the palette of available colours.
///
/// Normally these shouldn't be necessary, however in practice we may need
@@ -29,16 +30,16 @@ public final nonisolated class CompoundUIColors {
/// The main semantic tokens generated from the Style Dictionary.
private let tokens = CompoundUIColorTokens()
/// Runtime overrides for the `tokens` property.
private var overrides = [KeyPath<CompoundUIColorTokens, UIColor>: UIColor]()
private let overrides = Mutex<[KeyPath<CompoundUIColorTokens, UIColor> & Sendable: UIColor]>(.init())
public subscript(dynamicMember keyPath: KeyPath<CompoundUIColorTokens, UIColor>) -> UIColor {
overrides[keyPath] ?? tokens[keyPath: keyPath]
public subscript(dynamicMember keyPath: KeyPath<CompoundUIColorTokens, UIColor> & Sendable) -> UIColor {
overrides.withLock { $0[keyPath] } ?? tokens[keyPath: keyPath]
}
/// Customise the colour at the specified key path with the supplied colour.
/// Supplying `nil` as the colour will remove any existing customisation.
public func override(_ keyPath: KeyPath<CompoundUIColorTokens, UIColor>, with color: UIColor?) {
overrides[keyPath] = color
public func override(_ keyPath: KeyPath<CompoundUIColorTokens, UIColor> & Sendable, with color: UIColor?) {
overrides.withLock { $0[keyPath] = color }
}
// MARK: - Awaiting Semantic Tokens