UIActivity is not annotated with concurrency information. Does anyone know if subclasses you create will always run on the @MainActor ?
Is it safe to assume UIActivity is isolated to MainActor?
Thanks for the post.
In this case, yes, you can safely assume that your UIActivity subclass methods will always run on the main thread.
Even though the UIActivity base class currently lacks the explicit @MainActor annotation in the UIKit headers. The documentation explicitly states:
"The system calls the methods of your custom activity on the main thread."
https://developer.apple.com/documentation/UIKit/UIActivity?changes=l_4_4_8_2__8&language=objc
https://developer.apple.com/documentation/uikit/uiactivity/perform()?changes=___7&language=objc
Because of this, it is highly recommended that you explicitly annotate your own subclass with @MainActor. This bridges the gap for the Swift compiler, ensuring you don't get strict concurrency warnings when interacting with other UI components.
Will it run on the main thread? Yes, UIKit canPerform, prepare, performActivity, etc., are invoked on the main thread. Add @MainActor to your subclass so the Swift 6 compiler understands the context and enforces thread safety.
Hope this helps, looking for other comments from the team.
Albert Pascual Worldwide Developer Relations.