has non-Sendable type
⟩
Last updated
Was this helpful?
⟩
Last updated
Was this helpful?
Swift ⟩ Concurrency ⟩ Sendable ⟩ has non-Sendable type
Stored property 'shape
' of 'Sendable'-conforming struct 'MyAnyShape
' has non-sendable type '(CGRect)->Path
'
MyAnyShape
遵循 Shape,但 Shape 隱含遵循 Sendable 的規定(用於 Concurrency 的安全保障)。
Sendable
要求 struct
中所有屬性也必須是 Sendable
。
但 shape
屬性是閉包(closure),並不自動符合 Sendable,因為它可能捕獲非 Sendable 的值。
Swift Concurrency 的影響
在 Swift 5.5 或更高版本中,並行程式設計(Concurrency)會對某些類型進行更嚴格的型別檢查,特別是用於 @Sendable 閉包的情況。
應用: view.clipShape()
Shape: must be Sendable.
AnyShape:type-erased shape value.