I have code like this (which I also believe is quite common):
Network().fetchResource { response in
// Process response
}
Network is implemented in ObjC:
- (void)fetchResource:(void(^)(NSData *))completion {
// Simplified code to demo
dispatch_async(dispatch_get_global_queue(QOS_CLASS_BACKGROUND, 0), ^{
completion(data);
})
}
When the Swift code is called from a @MainActor context, say a method of a UIViewController , the callback crashes (dispatch_assert_queue failure) in Swift 6 mode because the Swift closure is inferred to be isolated to @MainActor but actually called on a background queue.
So my question is: how can I annotate the Swift closure to be non-isolated? I’ve tried all kinds of syntaxes but nothing works.