With Xcode 14.3, if I try to call loadItem
on NSItemProvider
, I get these warnings:
Non-sendable type '[AnyHashable : Any]?' exiting main actor-isolated context in call to non-isolated instance method 'loadItem(forTypeIdentifier:options:)' cannot cross actor boundary
Non-sendable type 'any NSSecureCoding' returned by call from main actor-isolated context to non-isolated instance method 'loadItem(forTypeIdentifier:options:)' cannot cross actor boundary
But I don't control the loadItem
function or NSSecureCoding
class. How can I avoid the sendable warnings?
Update: Interestingly if I take this function out of a UIViewController
subclass and keep it out of classes that use @MainActor
I do not get the warning.
John
func loadItem() async throws {
var attachment: NSItemProvider!
let loadedAttachment = try await attachment.loadItem(forTypeIdentifier: UTType.propertyList.identifier)
print("attachment: \(String(describing: attachment)), loadedAttachment: \(String(describing: loadedAttachment))")
}