Paddy O'Brien
06/02/2022, 2:45 PMsuspend
functions are available as functions with callbacks and async
functions in swift.
Unfortunately this means that interfaces with suspend
functions in Kotlin are exported as protocols with both async
and callback requirements in Swift. And async
is not supported for iOS 12 🙃
Is it possible to generate only the callback definitions?Paddy O'Brien
06/02/2022, 7:30 PM• Another issue is when an asynchronous completion-handler method is part of an Objective-C protocol. For example, the `NSURLSessionDataDelegate` protocol 1 includes this protocol requirement:
• - (void)URLSession:(NSURLSession*)session
• dataTask:(NSURLSessionDataTask *)dataTask
• didReceiveResponse:(NSURLResponse *)response
• completionHandler:(void (^)(NSURLSessionResponseDisposition disposition))completionHandler;
• Existing Swift code might implement this requirement in a conforming type using its completion-handler signature
• func URLSession(
• _ NSURLSession, dataTask: NSURLSessionDataTask, didReceiveResponse: NSURLResponse,
• completionHandler: (NSURLSessionResponseDisposition) -> Void) { ... }
• while Swift code designed to take advantage of the concurrency model would implement this requirement in a conforming type using itssignatureasync
• func URLSession(_ NSURLSession, dataTask: NSURLSessionDataTask, didReceiveResponse: NSURLResponse) async -> NSURLSessionResponseDisposition { ... }
• Implementing both requirements would produce an error (due to two Swift methods having the same selector), but under the normal Swift rules implementing only one of the requirements will also produce an error (because the other requirement is unsatisfied). Swift’s checking of protocol conformances will be extended to handle the case where multiple (imported) requirements have the same Objective-C selector: in that case, only one of them will be required to be implemented.