Created
September 21, 2022 17:02
-
-
Save zwaldowski/218f1dd11a10899635f0d256121f5d2b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// Captures a Cocoa object as a parameter to a `@Sendable` function or closure. | |
@propertyWrapper | |
public struct Copy<Wrapped>: @unchecked Sendable where Wrapped: NSCopying { | |
// from: <https://github.com/apple/swift-evolution/blob/main/proposals/0302-concurrent-value-and-concurrent-closures.md?plain=1#L568> | |
public let wrappedValue: Wrapped | |
public init(wrappedValue: Wrapped) { | |
self.wrappedValue = wrappedValue.copy() as! Wrapped // swiftlint:disable:this force_cast | |
} | |
} | |
extension Copy: Equatable where Wrapped: Equatable {} | |
extension Copy: Hashable where Wrapped: Hashable {} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment