16

I am using the new Swift 5.5 features to create an async function:

@MainActor
@objc func updateStatus() async {
    /// do async stuff...
}

But when I try to call this method from Objective-C code, it doesn't show up in autocomplete and gives a build error if I try to build it:

if (@available(iOS 15.0, *)) {
     CJSubscriptionStatusCheck *backgroundStatusCheck = [[CJSubscriptionStatusCheck alloc] init];
     [backgroundStatusCheck updateStatus]; // No visible @interface for 'CJStatusCheck' declares the selector 'updateStatus'
}

My other swift code works fine with Objective-C so the setup is fine, but I'm not sure how the 'async' code can be used (if at all) with Objective-C. I can't find an answer to this with my research.

Thanks.

0

1 Answer 1

26

According to SE-0297 Concurrency Interoperability with Objective-C async methods get added completionHandler parameter automatically.

Therefore the method name should be something similar to updateStatusWithCompletionHandler: in Objective-C.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.