has non-Sendable type
⟩
Last updated
Was this helpful?
⟩
Last updated
Was this helpful?
MyAnyShape
遵循 ,但 Shape 隱含遵循 的規定(用於 的安全保障)。
但 shape
屬性是閉包(),並不自動符合 Sendable,因為它可能捕獲非 Sendable 的值。
在 Swift 5.5 或更高版本中,並行程式設計()會對某些類型進行更嚴格的型別檢查,特別是用於 @Sendable 閉包的情況。
方案一:直接儲存 實例(wrappedShape
),而不是閉包(closure),完全避開 的問題。這樣的寫法具有較大的靈活性,如果你有很多種類的 ,建議用此寫法。
方案二:如果 類型有限,可用 來區分不同的形狀:
應用: view.clipShape()
⟩ ⟩ ⟩
Shape: must be Sendable.
AnyShape: shape value.