Dmitry Stakhov
03/21/2024, 12:41 PM// A.kt
interface AClass : BClass
interface BClass {
@NativeCoroutines
suspend fun foo()
}
class ImplClass : AClass {
override suspend fun foo() {
// do some work
}
}
I am currently using the version 0.13.2
, the generated ObjC code looks like this:
__attribute__((swift_name("BClass")))
@protocol ModulenameBClass
@required
/**
* @note This method converts instances of CancellationException to errors.
* Other uncaught Kotlin exceptions are fatal.
*/
- (void)fooWithCompletionHandler:(void (^)(NSError * _Nullable))completionHandler __attribute__((swift_name("foo(completionHandler:)")));
- (ModulenameKotlinUnit *(^(^)(ModulenameKotlinUnit *(^)(ModulenameKotlinUnit *, ModulenameKotlinUnit *), ModulenameKotlinUnit *(^)(NSError *, ModulenameKotlinUnit *)))(void))fooNative __attribute__((swift_name("fooNative()")));
@end
The fooNative
function is generated as the BClass
member here.
I am planning to update the library version to the latest 1.0.0-ALPHA26
, but I see the generated ObjC code looks like this now:
__attribute__((swift_name("BClass")))
@protocol ModulenameBClass
@required
@end
__attribute__((objc_subclassing_restricted))
__attribute__((swift_name("ANativeKt")))
@interface ModulenameANativeKt : AppPlatformBase
+ (ModulenameKotlinUnit *(^(^)(ModulenameKotlinUnit *(^)(ModulenameKotlinUnit *, ModulenameKotlinUnit *), ModulenameKotlinUnit *(^)(NSError *, ModulenameKotlinUnit *), ModulenameKotlinUnit *(^)(NSError *, ModulenameKotlinUnit *)))(void))foo:(id<ModulenameBClass>)receiver __attribute__((swift_name("foo(_:)")));
@end
The fooNative
function is generated as the ANativeKt
class static function with one parameter receiver
.
What is the best ways to handle this? Can I update to the latest library version keeping the function as the class member it's essentially added in Kotlin code?Rick Clephas
03/21/2024, 12:44 PMDmitry Stakhov
03/21/2024, 1:01 PMDmitry Stakhov
03/21/2024, 1:16 PMfooNative
function so writing the extensions can become necessary (or use with the static function as is) to make the project compatible with Kotlin 2.0Rick Clephas
03/21/2024, 1:18 PMDmitry Stakhov
03/21/2024, 2:06 PMRick Clephas
03/21/2024, 2:34 PM