I have an objective-c protocol:
@protocol MyDelegate <NSObject>
- (void)presentationFunc1:(MyViewModelType)viewModel;
- (void)presentationFunc2:(MyCompletionBlockType)completionHandler;
@end
These functions should be called on the main thread only. Since this protocol is implemented by objects in Swift files, I want to make it a @MainActor protocol.
I tried both the approach of adding:
NS_SWIFT_UI_ACTOR @protocol MyDelegate <NSObject>
- (void)presentationFunc1:(MyViewModelType)viewModel;
- (void)presentationFunc2:(MyCompletionBlockType)completionHandler;
@end
And:
@protocol MyDelegate <NSObject>
- (void)presentationFunc1:(MyViewModelType)viewModel NS_SWIFT_UI_ACTOR;
- (void)presentationFunc2:(MyCompletionBlockType)completionHandler NS_SWIFT_UI_ACTOR;
@end
And in both cases, while I do see some effect**, there's no nonisolated context error when calling those methods outside the main thread.
I also tried defining a similar protocol in Swift:
protocol MyDelegateSwift: NSObjectProtocol {
func presentationFunc1(viewModel: MyViewModel)
func presentationFunc2(completionHandler: MyCompletionBlockType)
}
Attempting to call presentationFunc1/2 outside the main thread does result in the desired Call to main actor-isolated instance method 'presentationFunc...' in a synchronous nonisolated context error.
**What I do see is that another object of mine, let's call it MyMainActor, that is a main actor and implements this method, no longer shows the following warning: Main actor-isolated instance method 'presentationFunc1(with:)' cannot be used to satisfy nonisolated protocol requirement; this is an error in the Swift 6 language mode. So it does have some effect, but still not showing the desired isolation error.
Can someone shed some light on this?
Thank you!