Hi folks,
I'm trying to update some Objective-C code to be friendlier with respect to Swift Concurrency. In this case, I have a protocol definition like this:
@import Foundation;
typedef void (^FooAction)(void);
@protocol Foo
@property (nonatomic, nullable) FooAction didDoFoo;
- (void)doFoo;
@end
I have a Swift class in another module that needs to be able to conform to that protocol. In this case, I need to attribute FooAction
with @MainActor to express the guarantees of the callers from Objective-C.
class Bar: NSObject, Foo {
var didDoFoo: FooAction?
func `do`() {
Task {
await didDoFoo?()
}
}
}
No matter where I try attributing NS_SWIFT_UI_ACTOR
to the FooAction
typedef, if I create an instance of Bar
and try setting didDoFoo
, I get errors that "converting function value...loses global actor 'MainActor'". Is this interaction between Objective-C and Swift supported, and if so, what is the proper way to attribute an Objective-C typedef for the main actor?