I'm trying to use NSImage
with Task
s. Nominally that requires it be Sendable
, but it is explicitly not Sendable
for some reason:
@available(*, unavailable)
extension NSImage : @unchecked Sendable {
}
…even though it is explicitly 'sendable' if used correctly (i.e. not concurrently), and has critical use-cases which require it to be passed between threads. Note that I'm pointing to Apple's own documentation on these points, to emphasise the inconsistencies here.
I'm at a loss to come up with any workarounds which aren't absurd (e.g. saving the image to a file - even if only in-memory - and reconstituting it on the other thread). Since I don't control the type, I can't declare it Sendable
. About the best I can think of is silliness like:
struct NSImageFixed: @unchecked Sendable {
let image: NSImage
}
…but please tell me there's a better way.
(I did try searching this forum's archives, but there are so many topics about Sendable
that I couldn't find any that aid in this matter, even though surely there must be plenty. I also searched Apple's Dev Forums and found plenty of people hitting the same issue yet no viable solutions)